sqlitestore

package
v0.4.0-rc.3 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: 6 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 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

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 *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.

Jump to

Keyboard shortcuts

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