database

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	*sql.DB
	Driver string
}

DB wraps the sql.DB object and provides custom methods

func NewDB

func NewDB(db *sql.DB, driver string) *DB

NewDB creates a new DB instance

func (*DB) Count added in v0.0.4

func (db *DB) Count(tableName string) (int, error)

func (*DB) Delete

func (db *DB) Delete(model *model.Model, id interface{}) error

Delete removes a record from the database

func (*DB) Exec

func (db *DB) Exec(query string, args ...interface{}) (sql.Result, error)

Exec executes a query without returning any rows

func (*DB) GetByID

func (db *DB) GetByID(model *model.Model, id interface{}) (map[string]interface{}, error)

GetByID retrieves a single record by its ID

func (*DB) Insert

func (db *DB) Insert(model *model.Model, data map[string]interface{}) error

Insert inserts a new record into the database

func (*DB) Query

func (db *DB) Query(query string, args ...interface{}) ([]map[string]interface{}, error)

Query executes a query and returns the results

func (*DB) Update

func (db *DB) Update(model *model.Model, id interface{}, data map[string]interface{}) error

Update updates an existing record in the database

Jump to

Keyboard shortcuts

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