sqlDB

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2025 License: Apache-2.0 Imports: 21 Imported by: 2

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

func NewSQLDatabaseInstance(name, databaseURL string) *sql.DB

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

func (q *PageQuery[T]) Execute() (*types.Page[T], error)

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

func (q *PageQuery[T]) ExecuteInInstance(instance *sql.DB) (*types.Page[T], error)

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

func NewQuery[T any](ctx context.Context, query string, params ...any) *Query[T]

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

func (q *Query[T]) Many() ([]T, error)

Many returns a slice of T value.

No parameters are required. Returns a slice of T value and an error.

func (*Query[T]) ManyInInstance

func (q *Query[T]) ManyInInstance(instance *sql.DB) ([]T, error)

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.

func (*Query[T]) One

func (q *Query[T]) One() (*T, error)

One return a pointer of T value

No parameters. Returns a pointer of T and an error.

func (*Query[T]) OneInInstance

func (q *Query[T]) OneInInstance(instance *sql.DB) (*T, error)

OneInInstance retrieves a single item of type T for the given SQL instance.

instance: The *sql.DB instance to execute the query. Returns a pointer of 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

func NewStatement(ctx context.Context, query string, params ...any) *Statement

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

func (*Statement) Execute

func (s *Statement) Execute() error

Execute applies the statement in the database.

No parameters. Returns an error.

func (*Statement) ExecuteInInstance

func (s *Statement) ExecuteInInstance(instance *sql.DB) error

ExecuteInInstance executes the statement in the provided database instance.

instance: the sql database instance to execute the statement in. Returns an error.

Jump to

Keyboard shortcuts

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