Programming

SQLite

What is SQLite?

D. Richard Hipp wrote SQLite in 2000. The engine is placed inside the program. It does not wait for another process. All the tables usually sit in one .sqlite or .db file. The SQL language is used here too, but the engine is not MySQL. MySQL is a separate server, and many people can write at the same time. SQLite is comfortable with one writer, and it also allows many readers. The difference from Python is this: Python runs the program, and SQLite keeps the rows. Python's standard library has sqlite3, and it opens the file with that. The difference from Node.js is this too: Node runs JavaScript. It can open a SQLite file with a package, or with newer Node's own module. Old Node does not have that module.

What is SQLite used for?

SQLite is for one user's data, or one device's data. A setting, a note, and a small catalog are its place.

  • A phone app's local database
  • A note the browser keeps
  • A desktop program's setting
  • A small site's one-file database

What can you do with SQLite?

With SQLite you create a table, add a row, and choose by a condition. A backup is a copy of that file. Writing to the same file from many servers at the same time is not its job. For a large site's order, a database with its own server is chosen.

Is SQLite hard to learn?

Opening the file is easy. The difficulty is writing at the same time. When two processes change the same row, one waits. If the wait grows long, the command stops. Moving the file to another folder also changes the program's path. Pasting a user's text into the SQL opens injection here too.

Advantages and limits

Advantage: there is no server to install, a copy is one file, and SQL is familiar. Limit: it gets tight for many writers and a large load. SQLite is not the small name of MySQL. It is an engine that works inside a file.

Basic ideas

The file is the database itself. A table is the names of the columns. A row is one record.

  • There is no separate server process
  • An SQL query is used here too
  • One writer is comfortable
  • A backup is a copy of the file

A short example

This query opens one table. If the file is missing, the engine can create it. There is no need to connect to a server.

CREATE TABLE note (
  id INTEGER PRIMARY KEY,
  text TEXT
);

Common questions

  • Are SQLite and Python the same? No. Python runs the program. SQLite keeps the rows. Python opens the file with the standard sqlite3.
  • Are SQLite and Node.js the same? No. Node runs JavaScript. It can open a SQLite file with a package, or with newer Node's own module. Old Node does not have that module.
  • Are SQLite and MySQL the same? No. Both use SQL. SQLite is one file, MySQL is a separate server.