sqlitestore

package
v0.4.0-rc.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

func Open(ctx context.Context, path string) (*sqlstore.Store, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL