sqlite

package
v0.1.24 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Attach

func Attach(dbfile string, dbname string) error

Attach attaches an additional SQLite database file (dbfile) to the default database connection under the schema alias dbname using the SQLite ATTACH DATABASE statement.

func InitDefault

func InitDefault(conf *Config) error

InitDefault opens SQLite and stores it as the dbsqlx default database.

Example

ExampleInitDefault shows the default-instance pattern: call InitDefault once at application startup, then retrieve the shared *sqlx.DB via dbsqlx.Default().

package main

import (
	"fmt"

	"github.com/phcp-tech/common-library-golang/dbsqlx"
	"github.com/phcp-tech/common-library-golang/dbsqlx/sqlite"
)

func main() {
	err := sqlite.InitDefault(&sqlite.Config{Path: ":memory:"})
	fmt.Println(err == nil)
	fmt.Println(dbsqlx.Default() != nil)
}
Output:
true
true

func NewSQLite

func NewSQLite(conf *Config) (*sqlx.DB, error)

NewSQLite opens a SQLite-backed *sqlx.DB and applies the standard PRAGMA settings (WAL, foreign keys, busy timeout, cache size). The parent directory of a file-based path is created automatically if absent.

Example

ExampleNewSQLite shows how to open an in-memory SQLite database. In-memory databases are useful for tests and ephemeral data — all data is lost when the connection is closed.

package main

import (
	"fmt"

	"github.com/phcp-tech/common-library-golang/dbsqlx/sqlite"
)

func main() {
	db, err := sqlite.NewSQLite(&sqlite.Config{Path: ":memory:"})
	fmt.Println(err == nil)
	fmt.Println(db != nil)
}
Output:
true
true

Types

type Config

type Config struct {
	// Path is the path to the SQLite database file, or ":memory:" for an
	// in-memory database. URI format is also supported, e.g.
	// "file:app.db?_journal_mode=WAL&_foreign_keys=on".
	Path string
}

Config contains SQLite connection settings.

Directories

Path Synopsis
Package component provides sqlx SQLite lifecycle integration for bootstrap.
Package component provides sqlx SQLite lifecycle integration for bootstrap.
Package vfs opens a SQLite database embedded inside a Go binary using modernc.org/sqlite/vfs and Go's embed.FS.
Package vfs opens a SQLite database embedded inside a Go binary using modernc.org/sqlite/vfs and Go's embed.FS.

Jump to

Keyboard shortcuts

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