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 ¶
- func ApplyLitestreamConnectionPragmas(ctx context.Context, orm *bun.DB, engine string) error
- func ApplySQLiteConnectionPragmas(ctx context.Context, orm *bun.DB, engine, dsn string) error
- func BuildPostgresDSN(c *models.DriverCredentials) (string, error)
- func EngineIsSQLiteLike(engine string) bool
- func ErrCredentialsRequired() error
- func IsAlreadyExistsErr(err error) bool
- func OpenBun(cfg *models.Config, cred *models.DriverCredentials) (*bun.DB, error)
- func QuoteMySQLIdent(s string) string
- func QuotePGIdent(s string) string
- type Base
- type BunDriver
- type Dialect
- type Driver
- type SQLDriverCarrier
- type SyncLocker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyLitestreamConnectionPragmas ¶
ApplyLitestreamConnectionPragmas configures SQLite for embedded Litestream local files.
func ApplySQLiteConnectionPragmas ¶
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 ¶
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 ¶
IsAlreadyExistsErr reports duplicate database/schema errors during bootstrap DDL.
func QuoteMySQLIdent ¶
QuoteMySQLIdent returns a MySQL backtick-quoted identifier for DDL.
func QuotePGIdent ¶
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 ¶
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 ¶
WithWriteLock runs fn while holding SQLite-like write serialization when applicable.
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.
type SQLDriverCarrier ¶
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).