Coming from SQLite
How to move from an embedded SQLite file to a Raft DB server with a MySQL or PostgreSQL driver, what differs in dialect and typing, and what you give up (running inside the application).
SQLite is a library inside your program; Raft DB is a server. The move is worth it when several programs or machines need the same data, when you want replication, or when one file is no longer enough. It is not worth it for a single-user program that benefits from having no server at all.
Choose a dialect#
Use the MySQL or MariaDB front-end (port 3306) or the PostgreSQL front-end (port 5432), whichever driver your language already has. Neither dialect is identical to SQLite's, so expect to edit some statements.
What changes#
| SQLite | Raft DB through a SQL front-end |
|---|---|
| Any column holds any type (dynamic typing) | Columns have types and values are checked; define the types |
INTEGER PRIMARY KEY is the row id | AUTO_INCREMENT (MySQL dialect) or a sequence / identity (PostgreSQL dialect) |
datetime('now'), strftime | NOW(), DATE_FORMAT (MySQL) or to_char (PostgreSQL) |
PRAGMA ... | server settings; most pragmas have no equivalent |
INSERT OR REPLACE | REPLACE INTO or INSERT ... ON DUPLICATE KEY UPDATE (MySQL dialect) |
| Foreign keys off unless enabled | enforced when declared |
| One writer at a time (file lock) | many sessions; isolation is per table at READ-COMMITTED |
| ` |
Moving the data#
sqlite3 app.db .dump > app.sqlgives a SQL script in SQLite's dialect. Edit theCREATE TABLEstatements to real types and removePRAGMA,BEGIN TRANSACTION/COMMITlines andsqlite_sequencerows.- Load it with
mysqlorpsqlagainst Raft DB, or export each table as CSV (.mode csv) and useLOAD DATAorCOPY. - Compare row counts table by table, and run the application's test suite against the new connection string.
What you give up#
The program no longer owns its data file: there is a server to install, secure and keep running. In exchange, several applications can share the data, it can be replicated, and the Studio and the tools can look at it.