lockless-fifo accepts sqlite

main
Bel LaPointe 2025-12-11 10:00:25 -07:00
parent 90a3256b7b
commit ab05743d4e
2 changed files with 53 additions and 0 deletions

View File

@ -0,0 +1,7 @@
https://trychroma.com/engineering/wal3
(generally with S3 but this is fine)
1. GET (current_node, cksum) FROM head_pointer
1. INSERT node (previous_node) VALUES (head_pointer) RETURNING node.id
1. UPDATE head_pointer (current_node, cksum) VALUES (node.id, blockchain) IF head_pointer.cksum=cksum

View File

@ -0,0 +1,46 @@
package main
import (
"context"
"database/sql"
"flag"
"log"
"os"
"time"
"pg/src/with"
_ "github.com/lib/pq"
_ "modernc.org/sqlite"
)
func main() {
if err := with.Context(run); err != nil {
panic(err)
}
}
func run(ctx context.Context) error {
fs := flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
c := fs.String("c", "postgresql://pulsegres:pulsegres@localhost:15432", "conn string")
if err := fs.Parse(os.Args[1:]); err != nil {
panic(err)
}
return with.PSQL(ctx, *c, func(pg *sql.DB) error {
go with.Every(ctx, 5*time.Second, func() {
row := pg.QueryRowContext(ctx, `SELECT 1`)
var n int
if err := row.Err(); err != nil {
log.Println("query err:", err)
} else if err := row.Scan(&n); err != nil {
log.Println("scan err:", err)
} else {
log.Println("ping...")
}
})
<-ctx.Done()
return nil
})
}