sqladapter

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 16 Imported by: 1 module, 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 sqladapter implements the shared database/sql adapter used by the PostgreSQL and SQLite dialect packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

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

Adapter is a schema-aware database/sql adapter. Call Migrate explicitly before serving requests.

func New

func New(db *sql.DB, dialect Dialect) (*Adapter, error)

func NewWithOptions added in v1.1.0

func NewWithOptions(db *sql.DB, dialect Dialect, options Options) (*Adapter, error)

NewWithOptions is New with optional settings. A SchemaName is rejected for any dialect other than PostgreSQL.

func (*Adapter) Capabilities

func (adapter *Adapter) Capabilities() betterauth.AdapterCapabilities

func (*Adapter) CheckSchema added in v1.1.0

func (adapter *Adapter) CheckSchema(
	ctx context.Context,
	schema betterauth.Schema,
) ([]betterauth.SchemaFinding, error)

CheckSchema reads the live tables that schema writes and returns every problem DiffSchema finds. On PostgreSQL it looks only in the configured schema when one is set, and otherwise in the first schema on the search_path that holds a table or view with that name. It implements betterauth.SchemaChecker.

func (*Adapter) ConsumeOne

func (adapter *Adapter) ConsumeOne(ctx context.Context, query betterauth.DeleteQuery) (betterauth.Record, error)

func (*Adapter) Count

func (adapter *Adapter) Count(ctx context.Context, query betterauth.CountQuery) (int64, error)

func (*Adapter) Create

func (adapter *Adapter) Create(ctx context.Context, query betterauth.CreateQuery) (betterauth.Record, error)

func (*Adapter) Delete

func (adapter *Adapter) Delete(ctx context.Context, query betterauth.DeleteQuery) error

func (*Adapter) DeleteMany

func (adapter *Adapter) DeleteMany(ctx context.Context, query betterauth.DeleteQuery) (int64, error)

func (*Adapter) FindMany

func (adapter *Adapter) FindMany(ctx context.Context, query betterauth.FindManyQuery) ([]betterauth.Record, error)

func (*Adapter) FindOne

func (adapter *Adapter) FindOne(ctx context.Context, query betterauth.FindOneQuery) (betterauth.Record, error)

func (*Adapter) ID

func (adapter *Adapter) ID() string

func (*Adapter) IncrementOne

func (adapter *Adapter) IncrementOne(ctx context.Context, query betterauth.IncrementQuery) (betterauth.Record, error)

func (*Adapter) Migrate

func (adapter *Adapter) Migrate(ctx context.Context, schema betterauth.Schema) error

Migrate creates missing tables and indexes for the supplied merged schema. It is additive and never drops or rewrites an existing column.

func (*Adapter) SchemaName added in v1.1.0

func (adapter *Adapter) SchemaName() string

SchemaName returns the configured PostgreSQL schema, or "" when statements use the connection's search_path.

func (*Adapter) Transaction

func (adapter *Adapter) Transaction(ctx context.Context, callback func(betterauth.DatabaseAdapter) error) error

func (*Adapter) Update

func (adapter *Adapter) Update(ctx context.Context, query betterauth.UpdateQuery) (betterauth.Record, error)

func (*Adapter) UpdateMany

func (adapter *Adapter) UpdateMany(ctx context.Context, query betterauth.UpdateQuery) (int64, error)

func (*Adapter) WithSchema

func (adapter *Adapter) WithSchema(schema betterauth.Schema) (betterauth.DatabaseAdapter, error)

type Dialect

type Dialect string
const (
	PostgreSQL Dialect = "postgresql"
	SQLite     Dialect = "sqlite"
)

type Options added in v1.1.0

type Options struct {
	// SchemaName is the PostgreSQL schema (namespace) that holds Better
	// Auth's tables. When set, every statement names the table as
	// "schema"."table", so the adapter no longer depends on the connection's
	// search_path, and Migrate creates the schema before it creates tables.
	// It matches Better Auth's database.schemaName and is PostgreSQL only.
	SchemaName string
}

Options holds optional adapter settings.

type UnsafeMigrationError added in v1.1.0

type UnsafeMigrationError struct {
	Model string
	Field string
}

UnsafeMigrationError reports an additive migration that would add a required column without a static default to a populated table.

func (*UnsafeMigrationError) Error added in v1.1.0

func (err *UnsafeMigrationError) Error() string

Jump to

Keyboard shortcuts

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