Documentation
¶
Index ¶
- func AddToBuffer(ctx context.Context, model interface{}, bufferSize int) error
- func BatchInsertData(ctx context.Context, records interface{}, batchSize int, ...) error
- func Connect(cfg DBConfig) (*gorm.DB, error)
- func CreateTable(ctx context.Context, model interface{}, tableName ...string) error
- func DeleteData(ctx context.Context, model interface{}, conditions map[string]interface{}) error
- func ExecuteCustomQuery(ctx context.Context, query string, args ...interface{}) error
- func ExecuteQueryWithContext(ctx context.Context, query string, args []interface{}) error
- func FetchData(ctx context.Context, model interface{}, conditions map[string]interface{}) error
- func FlushBufferToDB(ctx context.Context) error
- func GetDB() *gorm.DB
- func InsertData(ctx context.Context, record interface{}) error
- func IsTableExists(ctx context.Context, model interface{}, tableName ...string) bool
- func RunMigrations(cfg DBConfig, migrationsDir string) error
- func StartBufferFlusher(ctx context.Context, interval time.Duration)
- func UpdateData(ctx context.Context, model interface{}, updates map[string]interface{}, ...) error
- type BatchInsertConfig
- type ConflictOption
- type DBConfig
- type Postgres
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddToBuffer ¶
If the buffer reaches the specified size, it flushes the buffer to the database.
func BatchInsertData ¶
func BatchInsertData(ctx context.Context, records interface{}, batchSize int, opts ...ConflictOption) error
BatchInsertData inserts multiple records in batches with optional conflict handling records must be a slice of structs, batchSize determines how many records per batch (0 = default)
func CreateTable ¶
CreateTable creates a table in the database based on the given model.
func DeleteData ¶
DeleteData deletes records from the specified table based on conditions.
func ExecuteCustomQuery ¶
ExecuteCustomQuery allows executing custom SQL queries.
func ExecuteQueryWithContext ¶
ExecuteQueryWithContext allows executing custom SQL queries with a context-based timeout.
func FlushBufferToDB ¶
FlushBufferToDB flushes the buffer to the database in a batch insert.
func InsertData ¶
InsertData inserts a record into the specified table
func IsTableExists ¶
IsTableExists checks if a table exists for a given model.
func RunMigrations ¶
RunMigrations applies migrations from the specified directory.
func StartBufferFlusher ¶
StartBufferFlusher starts a background goroutine to periodically flush the buffer to the database.
Types ¶
type BatchInsertConfig ¶
type BatchInsertConfig struct {
ConflictColumns []string
DoNothing bool
Updates map[string]interface{}
}
BatchInsertConfig holds configuration for batch insert operations
type ConflictOption ¶
type ConflictOption func(*BatchInsertConfig)
ConflictOption defines a function type for configuring conflict handling
func WithOnConflictDoNothing ¶
func WithOnConflictDoNothing(columns []string) ConflictOption
WithOnConflictDoNothing specifies columns to watch for conflicts and do nothing on conflict
func WithOnConflictDoUpdate ¶
func WithOnConflictDoUpdate(columns []string, updates map[string]interface{}) ConflictOption
WithOnConflictDoUpdate specifies columns to watch for conflicts and perform updates