{"modulePath":"github.com/apito-io/engine","version":"v1.7.4","isLatest":false,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package sqlcommon\n\nPackage sqlcommon holds shared SQL project driver logic and dialect hooks. Engine packages (sqlite, postgres, mysql, mariadb) provide connection init and Dialect implementations.\n\n## Functions\n\n```go\nfunc ApplyLitestreamConnectionPragmas(ctx context.Context, orm *bun.DB, engine string) error\n```\nApplyLitestreamConnectionPragmas configures SQLite for embedded Litestream local files.\n\n```go\nfunc ApplySQLiteConnectionPragmas(ctx context.Context, orm *bun.DB, engine, dsn string) error\n```\nApplySQLiteConnectionPragmas sets FK enforcement and performance-related PRAGMAs for SQLite/libsql.\n\n```go\nfunc BuildPostgresDSN(c *models.DriverCredentials) (string, error)\n```\nBuildPostgresDSN builds a libpq URL for pgdriver from credentials.\n\n```go\nfunc EngineIsSQLiteLike(engine string) bool\n```\nEngineIsSQLiteLike reports engines that use SQLite semantics (embedded SQLite, libsql, Turso).\n\n```go\nfunc ErrCredentialsRequired() error\n```\nErrCredentialsRequired is returned when driver credentials are missing.\n\n```go\nfunc IsAlreadyExistsErr(err error) bool\n```\nIsAlreadyExistsErr reports duplicate database/schema errors during bootstrap DDL.\n\n```go\nfunc OpenBun(cfg *models.Config, cred *models.DriverCredentials) (*bun.DB, error)\n```\nOpenBun opens a Bun handle for the given credentials (any supported SQL engine).\n\n```go\nfunc QuoteMySQLIdent(s string) string\n```\nQuoteMySQLIdent returns a MySQL backtick-quoted identifier for DDL.\n\n```go\nfunc QuotePGIdent(s string) string\n```\nQuotePGIdent returns a PostgreSQL double-quoted identifier for DDL.\n\n## Types\n\n```go\ntype Base struct {\n\tConf             *models.Config\n\tORM              *bun.DB\n\tDriverCredential *models.DriverCredentials\n\tSyncLock         SyncLocker\n\n\tDialect Dialect\n\t// contains filtered or unexported fields\n}\n```\nBase holds shared Bun ORM state for all SQL project drivers.\n\n```go\nfunc (b *Base) LockSQLiteWrite() bool\n```\nLockSQLiteWrite acquires SQLite-like write serialization when applicable.\n\n```go\nfunc (b *Base) RunInTxOrBypass(ctx context.Context, fn func(ctx context.Context, tx bun.IDB) error) error\n```\nRunInTxOrBypass runs fn on the bare connection for SQLite-like engines, else inside a transaction.\n\n```go\nfunc (b *Base) UnlockSQLiteWrite()\n```\nUnlockSQLiteWrite releases SQLite-like write serialization.\n\n```go\nfunc (b *Base) WithWriteLock(fn func() error) error\n```\nWithWriteLock runs fn while holding SQLite-like write serialization when applicable.\n\n```go\ntype BunDriver interface {\n\tBun() *bun.DB\n\tEngine() string\n}\n```\nBunDriver is implemented by all SQL project drivers for introspection tools.\n\n```go\ntype Dialect interface {\n\tEngine() string\n\tQuoteIdent(name string) string\n\tSupportsTransactionalDDL() bool\n\tIsSQLiteLike() bool\n\tIsRemoteSQLiteLikeTurso(d *Driver) bool\n\tPreferDDLRunInTx(d *Driver) bool\n\tRunDDLBatch(ctx context.Context, d *Driver, fn func(bun.IDB) error) error\n\tRootResolverQueryBuilder(conf *models.Config, param *models.CommonSystemParams, returnCount bool) (string, []interface{}, error)\n}\n```\nDialect captures engine-specific SQL behavior for the shared driver.\n\n```go\ntype Driver struct {\n\tBase\n}\n```\nDriver is the shared SQL project driver implementation used by engine packages.\n\n```go\nfunc OpenDriver(cfg *models.Config, cred *models.DriverCredentials, dialect Dialect) (*Driver, error)\n```\nOpenDriver opens a Bun handle and returns a Driver with the given dialect.\n\n```go\nfunc (d *Driver) Bun() *bun.DB\n```\nBun returns the Bun handle (for dbexplorer and pro wrappers).\n\n```go\nfunc (d *Driver) Close() error\n```\nClose releases the underlying Bun pool.\n\n```go\nfunc (d *Driver) Engine() string\n```\n\n```go\nfunc (d *Driver) Ping() error\n```\nPing verifies the connection is alive.\n\n```go\ntype SQLDriverCarrier interface {\n\tSQLDriverShell() *Driver\n\tSQLEngineName() string\n}\n```\nSQLDriverCarrier is implemented by open-core and pro SQL project drivers for dbexplorer unwrap.\n\n```go\ntype SyncLocker interface {\n\tLockForTx()\n\tUnlockForTx()\n}\n```\nSyncLocker optionally serializes foreground DB operations (legacy hook).\n\n","path":"github.com/apito-io/engine/database/project/sqlcommon","name":"sqlcommon","synopsis":"Package sqlcommon holds shared SQL project driver logic and dialect hooks.","isRedistributable":true}
