Documentation
¶
Overview ¶
Package sqlitestore is experimental: its API and documented formats may change in a minor release; see https://nsgo.games/docs/stability/.
Package sqlitestore opens a realtime.Store in a SQLite database file using the pure-Go modernc.org/sqlite driver (no cgo). It suits a single service process; several replicas sharing one database should use Postgres (package pgstore).
The package builds for every target except the web, because browsers have no local file system for the database and the realtime service runs on a server.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Open ¶
Open opens (creating when missing) the SQLite database at path, or a private in-memory database for ":memory:", and returns a *sqlstore.Store with the schema migrated. Close the store when the service stops.
Example ¶
Open creates a SQLite-backed realtime notification store.
package main
import (
"context"
"fmt"
"github.com/nsgo-dev/game/pkg/online/realtime"
"github.com/nsgo-dev/game/pkg/online/realtime/sqlitestore"
)
func main() {
ctx := context.Background()
store, err := sqlitestore.Open(ctx, ":memory:")
if err != nil {
fmt.Println(err)
return
}
defer func() { _ = store.Close() }()
n, err := store.Save(ctx, realtime.Notification{
To: "ana",
Code: realtime.CodeFriendRequest,
Subject: "New friend request",
Sender: "ben",
Persistent: true,
})
if err != nil {
fmt.Println(err)
return
}
page, err := store.List(ctx, "ana", "", 10)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(n.ID, len(page.Notifications), page.Notifications[0].Code)
}
Output: 1 1 -1
Types ¶
This section is empty.