Commands.open: def of bend-kit-commands@0.4.0.0 Import: import bend-kit-commands@0.4.0.0/commands.bend as Commands Lines 166-185 of bend-kit-commands@0.4.0.0/commands.bend: https://jend.leeeet.dev/read.txt?path=bend-kit-commands@0.4.0.0/commands.bend&start_line=166&end_line=185 import Base import bend-kit-sqlite@0.1.0.1/sqlite.bend as Sqlite # Opens or creates the tables at path. # wait is how many ms a write waits for another connection's transaction before it fails with SQLITE_BUSY (5). def open(path: String, wait: U32) -> Run(Store): do Run: +db : U32 <- Sqlite.db.open(path) sql(db, "PRAGMA busy_timeout = " ++ U32.show(wait)) sql(db, "CREATE TABLE IF NOT EXISTS commands_rows (k BLOB PRIMARY KEY, v BLOB NOT NULL) WITHOUT ROWID") sql(db, "CREATE TABLE IF NOT EXISTS commands_seen (id TEXT PRIMARY KEY, payload BLOB NOT NULL, kind INTEGER NOT NULL, result BLOB NOT NULL, at INTEGER NOT NULL)") sql(db, "CREATE INDEX IF NOT EXISTS commands_seen_at ON commands_seen (at)") sql(db, "CREATE TABLE IF NOT EXISTS commands_outbox (seq INTEGER PRIMARY KEY AUTOINCREMENT, id TEXT NOT NULL, effect BLOB NOT NULL)") begin : U32 <- Sqlite.stmt.prepare(db, "BEGIN IMMEDIATE") commit : U32 <- Sqlite.stmt.prepare(db, "COMMIT") rollback : U32 <- Sqlite.stmt.prepare(db, "ROLLBACK") find : U32 <- Sqlite.stmt.prepare(db, "SELECT payload, kind, result, at FROM commands_seen WHERE id = ?") read : U32 <- Sqlite.stmt.prepare(db, "SELECT v FROM commands_rows WHERE k = ?") save : U32 <- Sqlite.stmt.prepare(db, "INSERT OR REPLACE INTO commands_rows (k, v) VALUES (?, ?)") del : U32 <- Sqlite.stmt.prepare(db, "DELETE FROM commands_rows WHERE k = ?") keep : U32 <- Sqlite.stmt.prepare(db, "INSERT INTO commands_seen (id, payload, kind, result, at) VALUES (?, ?, ?, ?, ?)") emit : U32 <- Sqlite.stmt.prepare(db, "INSERT INTO commands_outbox (id, effect) VALUES (?, ?)") return Store{db, begin, commit, rollback, find, read, save, del, keep, emit} Uses (12): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=String https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=String.append https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32 https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.show https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Unit https://jend.leeeet.dev/definition.txt?path=bend-kit-commands@0.4.0.0/commands.bend&name=Run https://jend.leeeet.dev/definition.txt?path=bend-kit-commands@0.4.0.0/commands.bend&name=Run.bind https://jend.leeeet.dev/definition.txt?path=bend-kit-commands@0.4.0.0/commands.bend&name=Run.pure https://jend.leeeet.dev/definition.txt?path=bend-kit-commands@0.4.0.0/commands.bend&name=Store https://jend.leeeet.dev/definition.txt?path=bend-kit-commands@0.4.0.0/commands.bend&name=sql https://jend.leeeet.dev/definition.txt?path=bend-kit-sqlite@0.1.0.1/sqlite.bend&name=db.open https://jend.leeeet.dev/definition.txt?path=bend-kit-sqlite@0.1.0.1/sqlite.bend&name=stmt.prepare