sqlite

package
v3.0.0-alpha.51 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// DBSource is the database URI to use.
	// The string ":memory:" can be used to create an in-memory database.
	// The sqlite driver can be configured through query parameters.
	// For more details see https://pkg.go.dev/modernc.org/sqlite#Driver.Open
	DBSource string
}

type Row

type Row = map[string]any

Row holds a single row in the result of a query. It is a key-value map where keys are column names.

type Rows

type Rows = []Row

Rows holds the result of a query as an array of key-value maps where keys are column names.

type SQLiteService

type SQLiteService struct {
	// contains filtered or unexported fields
}

func New

func New() *SQLiteService

New initialises a sqlite service with the default configuration.

func NewWithConfig

func NewWithConfig(config *Config) *SQLiteService

NewWithConfig initialises a sqlite service with a custom configuration. If config is nil, it falls back to the default configuration, i.e. an in-memory database.

The database connection is not opened right away. A call to [Service.Open] must succeed before using all other methods. If the service is registered with the application, [Service.Open] will be called automatically at startup.

func (*SQLiteService) Close

func (s *SQLiteService) Close() error

Close closes the current database connection if one is open, otherwise has no effect. Additionally, Close closes all open prepared statements associated to the connection.

Even when a non-nil error is returned, the database service is left in a consistent state, ready for a call to [Service.Open].

func (*SQLiteService) ClosePrepared

func (s *SQLiteService) ClosePrepared(stmt *Stmt) error

ClosePrepared closes a prepared statement obtained with [Service.Prepare] or [Service.PrepareContext]. ClosePrepared is idempotent: it has no effect on prepared statements that are already closed.

func (*SQLiteService) Configure

func (s *SQLiteService) Configure(config *Config)

Configure changes the database service configuration. The connection state at call time is preserved. Consumers will need to call [Service.Open] manually after Configure in order to reconnect with the new configuration.

See NewWithConfig for details on configuration.

func (*SQLiteService) ExecContext

func (s *SQLiteService) ExecContext(ctx context.Context, query string, args ...any) error

ExecContext executes a query without returning any rows. It supports early cancellation.

func (*SQLiteService) ExecPrepared

func (s *SQLiteService) ExecPrepared(ctx context.Context, stmt *Stmt, args ...any) error

ExecPrepared executes a prepared statement obtained with [Service.Prepare] or [Service.PrepareContext] without returning any rows. It supports early cancellation.

func (*SQLiteService) Execute

func (s *SQLiteService) Execute(query string, args ...any) error

Execute executes a query without returning any rows.

func (*SQLiteService) Open

func (s *SQLiteService) Open() error

Open validates the current configuration, closes the current connection if one is present, then opens and validates a new connection.

Even when a non-nil error is returned, the database service is left in a consistent state, ready for a new call to Open.

func (*SQLiteService) Prepare

func (s *SQLiteService) Prepare(query string) (*Stmt, error)

Prepare creates a prepared statement for later queries or executions. Multiple queries or executions may be run concurrently from the returned statement.

The caller should call the statement's Close method when it is no longer needed. Statements are closed automatically when the connection they are associated with is closed.

func (*SQLiteService) PrepareContext

func (s *SQLiteService) PrepareContext(ctx context.Context, query string) (*Stmt, error)

PrepareContext creates a prepared statement for later queries or executions. Multiple queries or executions may be run concurrently from the returned statement.

The caller must call the statement's Close method when it is no longer needed. Statements are closed automatically when the connection they are associated with is closed.

PrepareContext supports early cancellation.

func (*SQLiteService) Query

func (s *SQLiteService) Query(query string, args ...any) (Rows, error)

Query executes a query and returns a slice of key-value records, one per row, with column names as keys.

func (*SQLiteService) QueryContext

func (s *SQLiteService) QueryContext(ctx context.Context, query string, args ...any) (Rows, error)

QueryContext executes a query and returns a slice of key-value records, one per row, with column names as keys. It supports early cancellation, returning the slice of results fetched so far.

func (*SQLiteService) QueryPrepared

func (s *SQLiteService) QueryPrepared(ctx context.Context, stmt *Stmt, args ...any) (Rows, error)

QueryPrepared executes a prepared statement obtained with [Service.Prepare] or [Service.PrepareContext] and returns a slice of key-value records, one per row, with column names as keys. It supports early cancellation, returning the slice of results fetched so far.

func (*SQLiteService) ServiceName

func (s *SQLiteService) ServiceName() string

ServiceName returns the name of the plugin. You should use the go module format e.g. github.com/myuser/myplugin

func (*SQLiteService) ServiceShutdown

func (s *SQLiteService) ServiceShutdown() error

ServiceShutdown closes the database connection. It returns a non-nil error in case of failures.

func (*SQLiteService) ServiceStartup

func (s *SQLiteService) ServiceStartup(ctx context.Context, options application.ServiceOptions) error

ServiceStartup opens the database connection. It returns a non-nil error in case of failures.

type Stmt

type Stmt struct {
	// contains filtered or unexported fields
}

Stmt wraps a prepared sql statement pointer. It provides the same methods as the sql.Stmt type.

func (*Stmt) Close

func (s *Stmt) Close() error

Close closes the statement. It has no effect when the statement is already closed.

func (*Stmt) MarshalText

func (s *Stmt) MarshalText() ([]byte, error)

func (*Stmt) UnmarshalText

func (s *Stmt) UnmarshalText(text []byte) error

Jump to

Keyboard shortcuts

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