Tornado – SQLite

I received a couple of requests for Tornado’s interaction with SQLite interface. So, here’s the blog…

SQLite is a file based and transactional database engine. Because of it’s lightweight capabilities, SQLite’s adoption has increased in the recent past. You can know more about it here. Below is an example of Tornado’s interaction with SQLite DB.

Consider a SQLite DB having table ‘stud’ with schema as below:

stud    table    CREATE TABLE stud (id INTEGER PRIMARY KEY, marks NUMERIC, name TEXT)
id    field    INTEGER PRIMARY KEY
name    field    NUMERIC
marks    field    TEXT

In Tornado, we implement two pages:

  • http://localhost:8888/create – To add student record in DB
  • http://localhost:8888/show – To show all the existing records

Code snippets implementing this in Tornado can be viewed below:

Step 1: When user logs in to http://localhost:8888/create, he adds name and marks for a student. [Student id is auto generated]

Step 2: When user clicks on ‘Add’, a record gets added successfully

Step 3: Clicking on ‘Show Records’ shows all the records user has added to ‘stud’ table.

3 thoughts on “Tornado – SQLite

  1. good job (and) …. I have a question … How I can delete any item in the database from my website …

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.