Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Initialize ¶
func Initialize()
Initialize start connection with sql database and execute migration.
No parameters. No return values.
func NewSQLDatabaseInstance ¶
NewSQLDatabaseInstance creates a new SQL database instance.
Parameters: - name: a string representing the name of the database. - databaseURL: a string representing the URL of the database. Returns a pointer to sql.DB.
func NewTransaction ¶
func NewTransaction(isolation ...sql.IsolationLevel) transaction.Transaction
NewTransaction creates a new sqlTransaction implementing the transaction.Transaction interface.
It takes an optional variable number of sql.IsolationLevel parameters and returns a transaction.Transaction.
Types ¶
type PageQuery ¶
type PageQuery[T any] struct { // contains filtered or unexported fields }
PageQuery is a struct for sql page query
func NewPageQuery ¶
func NewPageQuery[T any](ctx context.Context, page *types.PageRequest, query string, params ...any) *PageQuery[T]
NewPageQuery creates a new pointer to PageQuery struct.
ctx: the context.Context for the query page: the types.PageRequest for the query query: the query string to execute params: variadic any for additional parameters Returns a pointer to PageQuery struct
func (*PageQuery[T]) Execute ¶
Execute returns a pointer of a page type with slice of T data.
No parameters. Returns a pointer to PageQuery struct and an error.
func (*PageQuery[T]) ExecuteInInstance ¶
ExecuteInInstance executes the page query in the given database instance.
Parameters: - instance: the database instance to execute the query in. Returns a Page of type T and an error.
type Query ¶
type Query[T any] struct { // contains filtered or unexported fields }
Query is a struct for an SQL query
func NewCachedQuery ¶
func NewCachedQuery[T any](ctx context.Context, cache *cacheDB.Cache[T], query string, params ...any) (q *Query[T])
NewCachedQuery create a new pointer to Query struct with cache.
ctx: the context.Context for the query cache: the cacheDB.Cache to store the query result query: the query string to execute params: variadic any for additional parameters Returns a pointer to Query struct
func NewQuery ¶
NewQuery create a new pointer to Query struct.
ctx: the context.Context for the query query: the query string to execute params: variadic any for additional parameters Returns a pointer to Query struct
func (*Query[T]) Many ¶
Many returns a slice of T value.
No parameters are required. Returns a slice of T value and an error.
func (*Query[T]) ManyInInstance ¶
ManyInInstance retrieves multiple items of type T for the given SQL instance.
instance: The *sql.DB instance to execute the query. Returns a slice of retrieved items type T and an error.
type SqlTxContextKey ¶
type SqlTxContextKey string
SqlTxContextKey is the type of the context key for the transaction.
const (
SqlTxContext SqlTxContextKey = "SqlTxContext"
)
type Statement ¶
type Statement struct {
// contains filtered or unexported fields
}
Statement is a struct for sql statement
func NewStatement ¶
NewStatement creates a new pointer to Statement struct.
ctx: the context.Context for the statement query: the query string for the statement params: variadic any for additional parameters Returns a pointer to Statement struct