sqlcommon

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package sqlcommon holds shared SQL project driver logic and dialect hooks. Engine packages (sqlite, postgres, mysql, mariadb) provide connection init and Dialect implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyLitestreamConnectionPragmas

func ApplyLitestreamConnectionPragmas(ctx context.Context, orm *bun.DB, engine string) error

ApplyLitestreamConnectionPragmas configures SQLite for embedded Litestream local files.

func ApplySQLiteConnectionPragmas

func ApplySQLiteConnectionPragmas(ctx context.Context, orm *bun.DB, engine, dsn string) error

ApplySQLiteConnectionPragmas sets FK enforcement and performance-related PRAGMAs for SQLite/libsql.

func BuildPostgresDSN

func BuildPostgresDSN(c *models.DriverCredentials) (string, error)

BuildPostgresDSN builds a libpq URL for pgdriver from credentials.

func EngineIsSQLiteLike

func EngineIsSQLiteLike(engine string) bool

EngineIsSQLiteLike reports engines that use SQLite semantics (embedded SQLite, libsql, Turso).

func ErrCredentialsRequired

func ErrCredentialsRequired() error

ErrCredentialsRequired is returned when driver credentials are missing.

func IsAlreadyExistsErr

func IsAlreadyExistsErr(err error) bool

IsAlreadyExistsErr reports duplicate database/schema errors during bootstrap DDL.

func OpenBun

func OpenBun(cfg *models.Config, cred *models.DriverCredentials) (*bun.DB, error)

OpenBun opens a Bun handle for the given credentials (any supported SQL engine).

func QuoteMySQLIdent

func QuoteMySQLIdent(s string) string

QuoteMySQLIdent returns a MySQL backtick-quoted identifier for DDL.

func QuotePGIdent

func QuotePGIdent(s string) string

QuotePGIdent returns a PostgreSQL double-quoted identifier for DDL.

Types

type Base

type Base struct {
	Conf             *models.Config
	ORM              *bun.DB
	DriverCredential *models.DriverCredentials
	SyncLock         SyncLocker

	Dialect Dialect
	// contains filtered or unexported fields
}

Base holds shared Bun ORM state for all SQL project drivers.

func (*Base) LockSQLiteWrite

func (b *Base) LockSQLiteWrite() bool

LockSQLiteWrite acquires SQLite-like write serialization when applicable.

func (*Base) RunInTxOrBypass

func (b *Base) RunInTxOrBypass(ctx context.Context, fn func(ctx context.Context, tx bun.IDB) error) error

RunInTxOrBypass runs fn on the bare connection for SQLite-like engines, else inside a transaction.

func (*Base) UnlockSQLiteWrite

func (b *Base) UnlockSQLiteWrite()

UnlockSQLiteWrite releases SQLite-like write serialization.

func (*Base) WithWriteLock

func (b *Base) WithWriteLock(fn func() error) error

WithWriteLock runs fn while holding SQLite-like write serialization when applicable.

type BunDriver

type BunDriver interface {
	Bun() *bun.DB
	Engine() string
}

BunDriver is implemented by all SQL project drivers for introspection tools.

type Dialect

type Dialect interface {
	Engine() string
	QuoteIdent(name string) string
	SupportsTransactionalDDL() bool
	IsSQLiteLike() bool
	IsRemoteSQLiteLikeTurso(d *Driver) bool
	PreferDDLRunInTx(d *Driver) bool
	RunDDLBatch(ctx context.Context, d *Driver, fn func(bun.IDB) error) error
	RootResolverQueryBuilder(conf *models.Config, param *models.CommonSystemParams, returnCount bool) (string, []interface{}, error)
}

Dialect captures engine-specific SQL behavior for the shared driver.

type Driver

type Driver struct {
	Base
}

Driver is the shared SQL project driver implementation used by engine packages.

func OpenDriver

func OpenDriver(cfg *models.Config, cred *models.DriverCredentials, dialect Dialect) (*Driver, error)

OpenDriver opens a Bun handle and returns a Driver with the given dialect.

func (*Driver) Bun

func (d *Driver) Bun() *bun.DB

Bun returns the Bun handle (for dbexplorer and pro wrappers).

func (*Driver) Close

func (d *Driver) Close() error

Close releases the underlying Bun pool.

func (*Driver) Engine

func (d *Driver) Engine() string

func (*Driver) Ping

func (d *Driver) Ping() error

Ping verifies the connection is alive.

type SQLDriverCarrier

type SQLDriverCarrier interface {
	SQLDriverShell() *Driver
	SQLEngineName() string
}

SQLDriverCarrier is implemented by open-core and pro SQL project drivers for dbexplorer unwrap.

type SyncLocker

type SyncLocker interface {
	LockForTx()
	UnlockForTx()
}

SyncLocker optionally serializes foreground DB operations (legacy hook).

Jump to

Keyboard shortcuts

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