Expand description
Runlight’s tables in the app’s own database, through sqlx and the app’s own pool.
use sqlx::sqlite::{SqliteConnectOptions, SqlitePool};
let pool = SqlitePool::connect_with(SqliteConnectOptions::new().filename("data/runlight.db").create_if_missing(true)).await?;
let store = runlight_sqlx::sqlite(pool);The tables are the TypeScript SDK’s, statement for statement, so a Rust
process can share a database with a Node or PHP one. Each database is a
feature of the crate: sqlite, postgres, and mysql (MySQL 8.4 or
MariaDB 11.4 and later).
Values reach the database as the TypeScript drivers send them. SQLite binds them typed, as better-sqlite3 does. Postgres and MySQL get them in the statement’s text, as node-postgres’s untyped parameters and mysql2’s client-side escaping do, so every statement means the same to the server as it does from Node: a value Postgres would infer the type of is written as a literal it infers the type of in the same way.
Structs§
- MysqlDb
- The store’s driver over a MySQL pool. SQL written for SQLite and Postgres is sent as MySQL reads it: a “quoted” name in backticks, a backslash inside ‘text’ doubled, and each value written into the statement, escaped, as mysql2 fills them in.
- Postgres
Db - The store’s driver over a Postgres pool. Values go in the statement’s text as literals of unknown type, so Postgres infers each one’s type as it does for node-postgres’s untyped parameters.
- Sqlite
Db - The pool, and the one connection of it the store holds. Statements and transactions take turns, so a request’s insert can never land inside an import’s open transaction, and a rollback can only undo the transaction’s own writes.
Functions§
- connect
- A store from a connection URL:
sqlite:(or a path),postgres://, ormysql://andmariadb://, with a pool of its own, as the standalone server and the CLI open one. - mysql
- Runlight’s tables in MySQL 8.4 or MariaDB 11.4 and later, on the app’s pool, which needs at least two connections. Text is utf8mb4 with a binary collation, so it compares and sorts by code point, as SQLite and Postgres do. Values are written into each statement escaped with backslashes, so each statement first takes NO_BACKSLASH_ESCAPES out of its connection’s sql_mode.
- postgres
- Runlight’s tables in Postgres, on the app’s pool. The pool needs at least two connections: some work holds one while it reads through another.
- sqlite
- Runlight’s tables in a SQLite database, on one connection of the app’s pool, which the store holds for its statements in turn (an in-memory database is one per connection, and SQLite has one writer at a time anyway). The connection is put in WAL mode with a busy timeout of five seconds.