orm

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2025 License: MIT Imports: 6 Imported by: 1

Documentation

Index

Constants

View Source
const (
	MySQL    = "mysql"
	Postgres = "postgres"
)

Database driver names.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	// contains filtered or unexported fields
}

DB provides main ORM interface.

func Open

func Open(dsn string) (*DB, error)

Open opens a MySQL database with default pooling. Deprecated: use OpenWithDriver to specify a driver explicitly.

func OpenWithDriver added in v0.1.0

func OpenWithDriver(driverName, dsn string) (*DB, error)

OpenWithDriver opens a database with default pooling for the given driver.

func (*DB) Begin added in v0.0.4

func (db *DB) Begin() (Tx, error)

Begin starts a transaction for manual control.

func (*DB) BeginTx added in v0.1.2

func (db *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (Tx, error)

BeginTx starts a transaction using ctx and returns the Tx.

func (*DB) Close

func (db *DB) Close() error

Close closes underlying DB.

func (*DB) Exec added in v0.0.3

func (db *DB) Exec(query string, args ...any) (sql.Result, error)

Exec executes a raw SQL statement.

func (*DB) ExecContext added in v0.0.3

func (db *DB) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)

ExecContext executes a raw SQL statement with a context.

func (*DB) Model

func (db *DB) Model(v any) *query.Query

Model creates a query for the struct table.

func (*DB) Query added in v0.0.3

func (db *DB) Query(q string, args ...any) (*sql.Rows, error)

Query runs a raw SQL query returning multiple rows.

func (*DB) QueryContext added in v0.0.3

func (db *DB) QueryContext(ctx context.Context, q string, args ...any) (*sql.Rows, error)

QueryContext runs Query with a context.

func (*DB) QueryRow added in v0.0.3

func (db *DB) QueryRow(query string, args ...any) *sql.Row

QueryRow executes a query that is expected to return at most one row.

func (*DB) QueryRowContext added in v0.0.3

func (db *DB) QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row

QueryRowContext executes a query with context returning at most one row.

func (*DB) SQLDB added in v0.0.5

func (db *DB) SQLDB() *sql.DB

SQLDB returns the underlying *sql.DB.

func (*DB) Table

func (db *DB) Table(name string) *query.Query

Table creates a query for table name.

func (*DB) Transaction

func (db *DB) Transaction(fn func(tx Tx) error) error

Transaction executes fn in a transaction.

func (*DB) TransactionContext added in v0.1.2

func (db *DB) TransactionContext(ctx context.Context, fn func(tx Tx) error) error

TransactionContext executes fn in a transaction using ctx.

type Tx

type Tx struct {
	*DB
	driver.Tx
}

Tx represents a transaction-scoped DB wrapper.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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