vlcn-io/cr-sqlite

Golang example

gedw99 opened this issue · 3 comments

gedw99 commented

https://vlcn.io/docs/cr-sqlite/installation Shows examples which is great .

is there a golang example floating around yet ?

Am thinking that Integration with Pocketbaae golang project is a great example as it is heavily invested in SQLite and highly popular.

https://github.com/pocketbase/pocketbase

it does real time using SSE networking . But crdt will provide scaleout for the server and offline for the client. Client is web based .

fly.io is already experimenting with its server shakeout aspects . The have LiteFS which is a WAL federation and sync system. But they are taking it further with crdt.

An example of just loading the extension?

Or an example of actually doing sync / something more involved?

I haven't coded in Go but this looks correct in terms of just getting the extension loaded and running: https://chat.openai.com/share/8ecef3c4-647e-4131-a636-3fa54c1ca1c5

In terms of doing sync, the API is exposed over SQL so the sync examples should apply without changes in any language.

https://vlcn.io/docs/networking/whole-crr-sync

Here is a better Go example:

package main

import (
    "database/sql"
    "fmt"

    sqlite3 "github.com/mattn/go-sqlite3"
)

func main() {
    sql.Register("sqlite3ext",
        &sqlite3.SQLiteDriver{
            Extensions: []string{
                "path/to/crsqlite",
            },
        })

    db, err := sql.Open("sqlite3ext", ":memory:")
    db.Query("select crsql_site_id()")
    db.Close()
}

You can load multiple extensions this way, just list them in the Extensions field.

Note that we use the same identifier sqlite3ext in the sql.Register and sql.Open.