SQLite
What and Why
- SQLite is not comparable with big client/server databases like Oracle, MySQL, PostgreSQL.
- SQLite is a file-based, simple, economical, reliable RDBMS.
When to use
- Embedded devices and IoT
- Like cellphones, set-top boxes, watches, drones.
- Application file format
- On-disk file format for desktop apps like VCS, record keeping programs.
- Websites
- Any low traffic site that gets fewer than 100K hits/day should work fine with SQLite (A rather conservative estimate).
See full list here
Use sqlite
Download. There are three releases for windows: x32 dll package, x64 dll package and exe package. Here let’s use exe package to demonstrate.
Run
sqlite3 test.db
in command line. This will create a database filetest.db
and start the REPL client for sqlite.Now just play with sql. Data will be persisted to
test.db
when the REPL client quits.
Node.js sqlite
Install: npm install sqlite3
You may encounter the following error:
1 | npm ERR! gyp ERR! find VS ************************************************************** |
Visual studio build tools are missing. The easiest way to install it is through choco
:
choco install visualstudio2017buildtools
If still not able to install sqlite3
after it, reboot the computer.
If still not able to install, repeatedly run the command until it is installed.
Sometimes sqlite3
cannot be installed with yarn add -dev
, try to install it with yarn add
and then modify package.json
and then install with yarn add -dev
.
Use:
As sqlite3
does not support Promise, there’s another wrapper library sqlite
which provides Promise:
MISC
- Create table if not exists:
1 | CREATE TABLE if not exists users(username TEXT primary key, email TEXT unqiue, password TEXT not null) |