2025-01-17 15:54:48 +05:30
|
|
|
package sqlstore
|
|
|
|
|
|
|
|
|
|
import (
|
2025-03-05 18:50:48 +05:30
|
|
|
"context"
|
2025-01-17 15:54:48 +05:30
|
|
|
"database/sql"
|
|
|
|
|
|
|
|
|
|
"github.com/jmoiron/sqlx"
|
|
|
|
|
"github.com/uptrace/bun"
|
|
|
|
|
)
|
|
|
|
|
|
2025-03-05 18:50:48 +05:30
|
|
|
type SQLStoreTxOptions = sql.TxOptions
|
|
|
|
|
|
2025-01-17 15:54:48 +05:30
|
|
|
type SQLStore interface {
|
|
|
|
|
// SQLDB returns the underlying sql.DB.
|
|
|
|
|
SQLDB() *sql.DB
|
2025-03-05 18:50:48 +05:30
|
|
|
|
2025-01-17 15:54:48 +05:30
|
|
|
// BunDB returns an instance of bun.DB. This is the recommended way to interact with the database.
|
|
|
|
|
BunDB() *bun.DB
|
2025-03-05 18:50:48 +05:30
|
|
|
|
|
|
|
|
// SQLxDB returns an instance of sqlx.DB. This is the legacy ORM used.
|
2025-01-17 15:54:48 +05:30
|
|
|
SQLxDB() *sqlx.DB
|
2025-03-05 18:50:48 +05:30
|
|
|
|
2025-03-06 15:39:45 +05:30
|
|
|
// Returns the dialect of the database.
|
|
|
|
|
Dialect() SQLDialect
|
|
|
|
|
|
2025-03-05 18:50:48 +05:30
|
|
|
// RunInTxCtx runs the given callback in a transaction. It creates and injects a new context with the transaction.
|
|
|
|
|
// If a transaction is present in the context, it will be used.
|
|
|
|
|
RunInTxCtx(ctx context.Context, opts *SQLStoreTxOptions, cb func(ctx context.Context) error) error
|
|
|
|
|
|
|
|
|
|
// BunDBCtx returns an instance of bun.IDB for the given context.
|
|
|
|
|
// If a transaction is present in the context, it will be used. Otherwise, the default will be used.
|
|
|
|
|
BunDBCtx(ctx context.Context) bun.IDB
|
2025-01-17 15:54:48 +05:30
|
|
|
}
|
2025-02-17 21:13:40 +05:30
|
|
|
|
|
|
|
|
type SQLStoreHook interface {
|
|
|
|
|
bun.QueryHook
|
|
|
|
|
}
|
2025-03-06 15:39:45 +05:30
|
|
|
|
|
|
|
|
type SQLDialect interface {
|
2025-03-25 04:05:40 +05:30
|
|
|
MigrateIntToTimestamp(context.Context, bun.IDB, string, string) error
|
|
|
|
|
MigrateIntToBoolean(context.Context, bun.IDB, string, string) error
|
2025-04-01 23:49:37 +05:30
|
|
|
AddNotNullDefaultToColumn(context.Context, bun.IDB, string, string, string, string) error
|
2025-03-25 04:05:40 +05:30
|
|
|
GetColumnType(context.Context, bun.IDB, string, string) (string, error)
|
|
|
|
|
ColumnExists(context.Context, bun.IDB, string, string) (bool, error)
|
|
|
|
|
RenameColumn(context.Context, bun.IDB, string, string, string) (bool, error)
|
2025-04-04 01:46:28 +05:30
|
|
|
RenameTableAndModifyModel(context.Context, bun.IDB, interface{}, interface{}, []string, func(context.Context) error) error
|
2025-04-04 01:25:24 +05:30
|
|
|
UpdatePrimaryKey(context.Context, bun.IDB, interface{}, interface{}, string, func(context.Context) error) error
|
|
|
|
|
AddPrimaryKey(context.Context, bun.IDB, interface{}, interface{}, string, func(context.Context) error) error
|
2025-03-06 15:39:45 +05:30
|
|
|
}
|