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 social.Store in a SQLite database file with the pure-Go modernc.org/sqlite driver (no cgo). It suits a single social service process; multiple processes sharing one database should use Postgres (package pgstore).
The package builds for every target except the web: browsers have no server-side SQLite file system.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var Dialect = sqlstore.Dialect{ Name: "sqlite", IsUnique: func(err error) bool { var e *sqlite.Error return errors.As(err, &e) && (e.Code() == constraintUnique || e.Code() == constraintPrimaryKey) }, }
Dialect is SQLite's sqlstore dialect. Open uses a single connection with _txlock=immediate, so write transactions run one at a time without needing row or advisory locks.
Functions ¶
func Open ¶
Open opens (creating when missing) the SQLite database at path, or a private in-memory database for ":memory:", and returns a social.Store with the schema migrated. The database enforces foreign keys, waits up to five seconds for busy locks, and uses WAL mode for file databases. Close the store to close the database.
Example ¶
Open migrates the social schema in SQLite and returns a social.Store.
package main
import (
"context"
"fmt"
"time"
"github.com/nsgo-dev/game/pkg/online/social"
"github.com/nsgo-dev/game/pkg/online/social/sqlitestore"
)
func main() {
ctx := context.Background()
store, err := sqlitestore.Open(ctx, ":memory:")
if err != nil {
fmt.Println(err)
return
}
defer store.Close()
now := time.Date(2026, 12, 2, 0, 0, 0, 0, time.UTC)
_, _ = store.AddFriend(ctx, "ana", "ben", social.AddLimits{MaxFriends: 100}, now)
res, _ := store.AddFriend(ctx, "ben", "ana", social.AddLimits{MaxFriends: 100}, now)
page, _ := store.Friends(ctx, "ana", social.StateFriend, "", 10)
fmt.Println(res, len(page.Edges), page.Edges[0].Other)
}
Output: accepted 1 ben
Types ¶
This section is empty.