Skip to main content

Module store

Module store 

Source
Expand description

Runlight’s tables: the database driver a store needs (Db), the rows it keeps, and SqlStore, the same tables and statements as the TypeScript SDK’s store on SQLite, Postgres, and MySQL or MariaDB. The drivers over sqlx are the runlight-sqlx crate.

Re-exports§

pub use prefixed::LOCK_WAIT;
pub use prefixed::PREFIX;
pub use prefixed::Prefixed;
pub use prefixed::TABLES;
pub use prefixed::TablesBusyError;
pub use prefixed::check_prefix;
pub use prefixed::lock_wait;

Macros§

params
Builds a parameter list: params![site, from, to].

Structs§

DbError
A database that refused a statement, or could not be reached.
EventRow
One recorded row: a pageview, event, engagement ping, link click, or AI agent fetch.
FunnelRow
Steps a visit is expected to take in order.
FunnelStep
One step of a funnel: reaching a page (with * as a wildcard), or sending an event.
GoalRow
Something worth counting.
GoalTotals
A goal’s totals.
LinkRow
A short link.
PageviewInfo
The pageview an engagement ping or event belongs to.
Prefixed
A Db whose tables and indexes start with a prefix in place of rl_, such as wp_rl_ inside WordPress, so two apps sharing one database each keep a set of their own. Runlight’s SQL names every table and index rl_ and something, and those names alone are rewritten on the way through, in each statement and in the names a schema check compares as text. Values bound as parameters are left as they are. A store given a prefix puts one in front of its Db, so the accounts and importers that reach the Db through the store follow it too.
ReportRow
Someone who gets a site’s report by email. token is the unsubscribe key.
Row
One row, its columns by name.
SessionRow
A visit, as recorded from its first request.
ShareRow
A public, read-only view of one site’s stats, opened by its unguessable id.
SiteRow
A site.
SqlStore
Runlight’s tables in a database: everything recorded, and every report read from it.
Stats
A range’s totals.
TablesBusyError
Another process held the lock for creating tables past the wait, such as one building an index on a big table after an upgrade. The request that waited fails with this, rather than waiting for good. It reaches the store as a DbError with its words, which TablesBusyError::of knows again.
TokenRow
An API token. Only its hash is stored; the token itself is shown once.

Enums§

Cell
A column’s value, as the driver gave it.
Dialect
The SQL a database speaks.
Hold
What a held connection is for.
Param
A statement’s parameter, in the types a JavaScript driver binds.

Constants§

BOUNCE_MS
A session’s bounce: one page, nothing clicked that was tracked, under ten seconds engaged.
EVENT_TAIL_MS
How long after a visit starts its events are looked for: far past any real visit.
JOURNEY_VISITS
The most visits journeys reads, newest first.
LOCK_WAIT
The longest a process waits for another one creating or upgrading the tables before it gives up.
MYSQL_COLLATION
MySQL’s text collation: UTF-8 compared and sorted by code point, case and trailing spaces included, as SQLite and Postgres’s “C” collation do. MariaDB has it too, from 11.4.
PREFIX
What every table and index name starts with, unless a store is given another prefix in its place.
TABLES
Runlight’s tables, after the prefix: the store’s, and the sign-in accounts’ two. An app dropping Runlight’s tables drops these by name, never every table that starts with the prefix.

Traits§

Db
The little a store needs from a database driver. SQL uses ? placeholders and “double quotes” around a name that is a keyword somewhere; a driver numbers the placeholders, or fills them in and quotes names its own way, as the TypeScript drivers do.

Functions§

check_prefix
Checks a table prefix, with the error the SDK throws for one that cannot be.
fill_placeholders
SQL written with ? placeholders and “double quoted” names, with each placeholder outside quotes filled in by fill, as node-postgres and mysql2 send values in the statement’s text. For MySQL, a “quoted” name goes in backticks and a backslash inside ‘text’ is doubled, since MySQL reads it as an escape where standard SQL takes it literally.
js_order
Compares as JavaScript’s < does: by UTF-16 code units.
lock_wait
How long a Db waits for the lock for creating tables: LOCK_WAIT, unless a test has set another.
mysql_literal
A value as a MySQL literal, as mysql2’s escape() writes the values Runlight binds, except that a quote is doubled rather than escaped with a backslash, so a value stays inside its quotes even on a connection whose sql_mode has NO_BACKSLASH_ESCAPES.
postgres_literal
A value as a Postgres literal of unknown type, which the server reads as it reads a parameter node-postgres sends untyped: E'...' text (backslashes and quotes escaped, whatever standard_conforming_strings says), numbers too, and NULL.

Type Aliases§

SiteOverrides
What the dashboard may change about a site, kept as the JSON object it was saved as ({ name?, timezone? }).