Documentation
¶
Index ¶
- func Count(db *sqlx.DB, driver Driver, query string, args ...any) (int64, error)
- func Find[T any](db *sqlx.DB, driver Driver, query string, resolver func(*T), args ...any) ([]T, error)
- func FindOne[T any](db *sqlx.DB, driver Driver, query string, resolver func(*T), args ...any) (*T, error)
- func Insert(db *sqlx.DB, entity any, table string, driver Driver) (sql.Result, error)
- func NewMySQLConnector(host string, username string, password string, database string) (*sqlx.DB, error)
- func NewPostgresConnector(host string, port string, user string, password string, database string) (*sqlx.DB, error)
- func ResolveInsert[T any](entity T, table string, driver Driver) (string, []any)
- func ResolveQuery[T any](query string, driver Driver) string
- func ResolveUpdate[T any](entity T, table string, driver Driver, condition string, args ...any) (string, []any)
- func Update(db *sqlx.DB, entity any, table string, driver Driver, condition string, ...) (sql.Result, error)
- type Driver
- type IDecoder
- type Query
- type QueryBuilder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Find ¶ added in v1.2.0
func Find[T any](db *sqlx.DB, driver Driver, query string, resolver func(*T), args ...any) ([]T, error)
Find get multiple entity (resolve entity from db struct tag)
You can pass resolver to manipulate record after read you can use `q` struct for advanced field select query
func FindOne ¶ added in v1.2.0
func FindOne[T any](db *sqlx.DB, driver Driver, query string, resolver func(*T), args ...any) (*T, error)
FindOne get single entity
You can pass resolver to manipulate record after read you can use `q` or `db` struct tag to map field to database column
func NewMySQLConnector ¶
func NewMySQLConnector(host string, username string, password string, database string) (*sqlx.DB, error)
NewMySQLConnector create new mysql connection
func NewPostgresConnector ¶ added in v1.1.0
func NewPostgresConnector(host string, port string, user string, password string, database string) (*sqlx.DB, error)
NewPostgresConnector create new POSTGRES connection
func ResolveInsert ¶ added in v1.2.0
ResolveInsert create insert cmd for table
@returns insert command and params as result
func ResolveQuery ¶ added in v1.2.0
ResolveQuery get list of fields from struct `q` and `db` tag and replace with `SELECT ...` keyword in query
Types ¶
type Driver ¶ added in v1.2.0
type Driver string
const DriverMySQL Driver = "mysql"
const DriverPostgres Driver = "postgres"
type QueryBuilder ¶
type QueryBuilder interface { // And add new simple condition to query with AND And(cond string, args ...any) // Or add new simple condition to query with OR Or(cond string, args ...any) // AndClosure add new condition to query with AND in nested () AndClosure(cond string, args ...any) // OrClosure add new condition to query with OR in nested () OrClosure(cond string, args ...any) // ToSQL generate query with placeholder based on counter ToSQL(counter int) string // Params get list of query parameters Params() []any }
func NewQuery ¶ added in v1.2.0
func NewQuery(driver Driver) QueryBuilder
NewQuery generate new query builder
Source Files
¶
Click to show internal directories.
Click to hide internal directories.