vlcn-io / cr-sqlite

Convergent, Replicated SQLite. Multi-writer and CRDT support for SQLite
https://vlcn.io
MIT License
2.77k stars 76 forks source link

Golang example #382

Closed gedw99 closed 10 months ago

gedw99 commented 12 months ago

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.

tantaman commented 11 months ago

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

nalgeon commented 11 months ago

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.

gedw99 commented 11 months ago

helpful : https://antonz.org/install-sqlite-extension/#install-go