this repo has no description
1package db 2 3import "database/sql" 4 5type DB struct { 6 *sql.DB 7} 8 9func Make(dbPath string) (*DB, error) { 10 db, err := sql.Open("sqlite3", dbPath) 11 if err != nil { 12 return nil, err 13 } 14 15 _, err = db.Exec(` 16 pragma journal_mode = WAL; 17 pragma synchronous = normal; 18 pragma foreign_keys = on; 19 pragma temp_store = memory; 20 pragma mmap_size = 30000000000; 21 pragma page_size = 32768; 22 pragma auto_vacuum = incremental; 23 pragma busy_timeout = 5000; 24 25 create table if not exists known_dids ( 26 did text primary key 27 ); 28 29 create table if not exists pipelines ( 30 rkey text not null, 31 pipeline text not null, -- json 32 primary key rkey 33 ); 34 `) 35 if err != nil { 36 return nil, err 37 } 38 39 return &DB{db}, nil 40} 41 42func (d *DB) SaveLastTimeUs(lastTimeUs int64) error { 43 _, err := d.Exec(` 44 insert into _jetstream (id, last_time_us) 45 values (1, ?) 46 on conflict(id) do update set last_time_us = excluded.last_time_us 47 `, lastTimeUs) 48 return err 49} 50 51func (d *DB) GetLastTimeUs() (int64, error) { 52 var lastTimeUs int64 53 row := d.QueryRow(`select last_time_us from _jetstream where id = 1;`) 54 err := row.Scan(&lastTimeUs) 55 return lastTimeUs, err 56}