dbsqlx

package
v0.1.32 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package dbsqlx is a thin wrapper around github.com/vinovest/sqlx (a database/sql extension with reflection-based struct scanning and Go generics). It does not replace sqlx or hide *sqlx.DB — its purpose is to make connection setup consistent across drivers while keeping normal query execution in plain sqlx.

The root package does not import concrete database drivers. Concrete drivers live in adapter packages (e.g. dbsqlx/sqlite), so applications only pull in the driver they actually use.

Index

Examples

Constants

View Source
const (
	MaxOpenConns    = 100              // MaxOpenConns is the maximum number of open database connections in the pool.
	MaxIdleConns    = 25               // MaxIdleConns is the maximum number of idle database connections (1/4 of MaxOpenConns).
	ConnMaxLifetime = 60 * time.Minute // ConnMaxLifetime is the maximum lifetime of a database connection.
	ConnMaxIdletime = 10 * time.Minute // ConnMaxIdletime is the maximum idle lifetime of a database connection.
)

Variables

View Source
var ErrMissingConfig = errors.New("dbsqlx: missing connection fields")

ErrMissingConfig is returned when an adapter lacks required connection fields.

Functions

func Close

func Close(db *sqlx.DB) error

Close closes the underlying database/sql connection for db.

Example

ExampleClose shows how to close a *sqlx.DB obtained from Open. Close is a no-op when db is nil.

package main

import (
	"fmt"

	"github.com/phcp-tech/common-library-golang/dbsqlx"

	"github.com/vinovest/sqlx"
	_ "modernc.org/sqlite"
)

// exDB opens a private in-memory SQLite database and creates the ex_products
// table. Each call returns an independent database — no shared state between
// examples. Uses the plain sqlite driver directly (not the dbsqlx/sqlite
// adapter) to keep these examples focused on the driver-agnostic root API.
func exDB() *sqlx.DB {
	db, err := dbsqlx.Open("sqlite", ":memory:", nil)
	if err != nil {
		panic("exDB: " + err.Error())
	}
	if _, err := db.Exec(`CREATE TABLE ex_products (
		id INTEGER PRIMARY KEY AUTOINCREMENT,
		name TEXT NOT NULL,
		category TEXT NOT NULL DEFAULT ''
	)`); err != nil {
		panic("exDB create table: " + err.Error())
	}
	return db
}

func main() {
	db := exDB()
	err := dbsqlx.Close(db)
	fmt.Println(err == nil)
}
Output:
true

func Default

func Default() *sqlx.DB

Default returns the process-wide default sqlx database instance.

Example

ExampleDefault shows how to retrieve the process-wide default *sqlx.DB.

package main

import (
	"fmt"

	"github.com/phcp-tech/common-library-golang/dbsqlx"

	_ "modernc.org/sqlite"
)

func main() {
	prev := dbsqlx.Default()
	dbsqlx.SetDefault(nil)
	defer dbsqlx.SetDefault(prev) // restore after example

	fmt.Println(dbsqlx.Default() == nil) // nil — not yet initialised
}
Output:
true

func Exec

func Exec(ctx context.Context, db sqlx.ExecerContext, query string, args ...any) (int64, error)

Exec executes a statement with positional arguments and returns the number of affected rows.

Example

ExampleExec shows how to run a statement and get the number of affected rows.

package main

import (
	"context"
	"fmt"

	"github.com/phcp-tech/common-library-golang/dbsqlx"

	"github.com/vinovest/sqlx"
	_ "modernc.org/sqlite"
)

// exDB opens a private in-memory SQLite database and creates the ex_products
// table. Each call returns an independent database — no shared state between
// examples. Uses the plain sqlite driver directly (not the dbsqlx/sqlite
// adapter) to keep these examples focused on the driver-agnostic root API.
func exDB() *sqlx.DB {
	db, err := dbsqlx.Open("sqlite", ":memory:", nil)
	if err != nil {
		panic("exDB: " + err.Error())
	}
	if _, err := db.Exec(`CREATE TABLE ex_products (
		id INTEGER PRIMARY KEY AUTOINCREMENT,
		name TEXT NOT NULL,
		category TEXT NOT NULL DEFAULT ''
	)`); err != nil {
		panic("exDB create table: " + err.Error())
	}
	return db
}

func main() {
	ctx := context.Background()
	db := exDB()
	db.MustExec(`INSERT INTO ex_products (name, category) VALUES (?, ?)`, "nail", "fasteners")
	db.MustExec(`INSERT INTO ex_products (name, category) VALUES (?, ?)`, "screw", "fasteners")

	rows, err := dbsqlx.Exec(ctx, db, `UPDATE ex_products SET category = ? WHERE category = ?`, "hardware", "fasteners")
	fmt.Println(err == nil)
	fmt.Println(rows)
}
Output:
true
2

func HealthChecker

func HealthChecker() health.Checker

HealthChecker returns a health.Checker that verifies database connectivity by pinging the default sqlx database.

The Checker is driver-agnostic — it works with any driver (MySQL, PostgreSQL, SQLite, …) that was used to initialise Default. Reports health.StatusUnhealthy when Default() is nil or when the ping fails; health.StatusHealthy when reachable.

Example

ExampleHealthChecker shows how to wire HealthChecker into a health.Check call for a /health HTTP endpoint.

package main

import (
	"context"
	"fmt"

	"github.com/phcp-tech/common-library-golang/dbsqlx"
	"github.com/phcp-tech/common-library-golang/health"

	_ "modernc.org/sqlite"
)

func main() {
	prev := dbsqlx.Default()
	dbsqlx.SetDefault(nil)
	defer dbsqlx.SetDefault(prev)

	results := health.Check(context.Background(), dbsqlx.HealthChecker())
	fmt.Println(results[0].Name)
	fmt.Println(results[0].Status == health.StatusUnhealthy) // true — Default() is nil
}
Output:
database
true

func IsSafeSQLIdentifierPath added in v0.1.26

func IsSafeSQLIdentifierPath(value string) bool

IsSafeSQLIdentifierPath reports whether value is a dot-separated path of safe SQL identifiers (e.g. "table.column"), guarding SortSql against injection via the Sort field. Exported so dialect packages building their own ORDER BY expressions (e.g. ChineseSortSql in dbsqlx/postgres) can validate a column name with the same rules.

func IsSafeSQLName added in v0.1.26

func IsSafeSQLName(value string) bool

IsSafeSQLName reports whether value is a safe single SQL identifier: letters, digits (not leading), and underscores only. Also usable to validate a charset/encoding name interpolated directly into SQL (e.g. by ChineseSortSql), since it follows the same safe-token shape.

func NamedExec

func NamedExec(ctx context.Context, db sqlx.ExtContext, query string, arg any) (int64, error)

NamedExec executes a named-parameter statement (e.g. "INSERT INTO t (name) VALUES (:name)") against arg — a struct or map[string]any providing the named values — and returns the number of affected rows.

Example

ExampleNamedExec shows how to run a statement with named parameters bound from a map. Named parameters improve readability for statements with many columns.

package main

import (
	"context"
	"fmt"

	"github.com/phcp-tech/common-library-golang/dbsqlx"

	"github.com/vinovest/sqlx"
	_ "modernc.org/sqlite"
)

// exDB opens a private in-memory SQLite database and creates the ex_products
// table. Each call returns an independent database — no shared state between
// examples. Uses the plain sqlite driver directly (not the dbsqlx/sqlite
// adapter) to keep these examples focused on the driver-agnostic root API.
func exDB() *sqlx.DB {
	db, err := dbsqlx.Open("sqlite", ":memory:", nil)
	if err != nil {
		panic("exDB: " + err.Error())
	}
	if _, err := db.Exec(`CREATE TABLE ex_products (
		id INTEGER PRIMARY KEY AUTOINCREMENT,
		name TEXT NOT NULL,
		category TEXT NOT NULL DEFAULT ''
	)`); err != nil {
		panic("exDB create table: " + err.Error())
	}
	return db
}

func main() {
	ctx := context.Background()
	db := exDB()

	rows, err := dbsqlx.NamedExec(ctx, db,
		`INSERT INTO ex_products (name, category) VALUES (:name, :category)`,
		map[string]any{"name": "chisel", "category": "tools"})
	fmt.Println(err == nil)
	fmt.Println(rows)
}
Output:
true
1
Example (Struct)

ExampleNamedExec_struct shows how to bind named parameters directly from a struct's db-tagged fields instead of a map.

package main

import (
	"context"
	"fmt"

	"github.com/phcp-tech/common-library-golang/dbsqlx"

	"github.com/vinovest/sqlx"
	_ "modernc.org/sqlite"
)

// exProduct is a minimal model used by the example functions.
type exProduct struct {
	ID       int64  `db:"id"`
	Name     string `db:"name"`
	Category string `db:"category"`
}

// exDB opens a private in-memory SQLite database and creates the ex_products
// table. Each call returns an independent database — no shared state between
// examples. Uses the plain sqlite driver directly (not the dbsqlx/sqlite
// adapter) to keep these examples focused on the driver-agnostic root API.
func exDB() *sqlx.DB {
	db, err := dbsqlx.Open("sqlite", ":memory:", nil)
	if err != nil {
		panic("exDB: " + err.Error())
	}
	if _, err := db.Exec(`CREATE TABLE ex_products (
		id INTEGER PRIMARY KEY AUTOINCREMENT,
		name TEXT NOT NULL,
		category TEXT NOT NULL DEFAULT ''
	)`); err != nil {
		panic("exDB create table: " + err.Error())
	}
	return db
}

func main() {
	ctx := context.Background()
	db := exDB()

	arg := exProduct{Name: "saw", Category: "tools"}
	rows, err := dbsqlx.NamedExec(ctx, db,
		`INSERT INTO ex_products (name, category) VALUES (:name, :category)`, arg)
	fmt.Println(err == nil)
	fmt.Println(rows)
}
Output:
true
1

func NormalizeSortDirection added in v0.1.26

func NormalizeSortDirection(direction string) string

NormalizeSortDirection returns direction upper-cased and trimmed, falling back to "ASC" when it is empty or not one of "ASC"/"DESC". Exported so dialect packages building their own ORDER BY expressions (e.g. ChineseSortSql in dbsqlx/postgres) apply the exact same direction rules SortSql does.

func Open

func Open(driverName, dsn string, conf *PoolConfig) (*sqlx.DB, error)

Open connects to driverName using dsn and verifies connectivity with an eager ping, then applies pool settings from conf. Zero-value or nil conf fields fall back to the package defaults (MaxOpenConns, MaxIdleConns, etc).

Example

ExampleOpen shows how to connect to a database with pool tuning. Open verifies connectivity with an eager ping before returning.

package main

import (
	"fmt"

	"github.com/phcp-tech/common-library-golang/dbsqlx"

	_ "modernc.org/sqlite"
)

func main() {
	db, err := dbsqlx.Open("sqlite", ":memory:", &dbsqlx.PoolConfig{
		MaxOpenConns: 4,
		MaxIdleConns: 2,
	})
	fmt.Println(err == nil)
	fmt.Println(db != nil)
}
Output:
true
true

func PageSql

func PageSql(para *dto.PageParameter) string

PageSql builds a LIMIT/OFFSET SQL clause from the pagination fields in para. When Limit is -1, all records are returned without a LIMIT clause. Defaults to page 1 and defaultPageLimit when values are unset or invalid; caps Limit at maxPageLimit and Page at maxPage.

Page and Limit are ints, not strings, so — unlike Sort — they carry no SQL injection risk: strconv.Itoa on an int can only ever produce a plain decimal digit string. The Page cap here is a resource-usage guard instead, not a security fix: without it, an arbitrarily large Page still produces a syntactically valid but enormous OFFSET that the database must count past before returning zero rows.

Example

ExamplePageSql shows how to build a LIMIT/OFFSET clause and append it to a raw SELECT statement for pagination.

package main

import (
	"context"
	"fmt"

	"github.com/phcp-tech/common-library-golang/dbsqlx"
	"github.com/phcp-tech/common-library-golang/dto"

	"github.com/vinovest/sqlx"
	_ "modernc.org/sqlite"
)

// exProduct is a minimal model used by the example functions.
type exProduct struct {
	ID       int64  `db:"id"`
	Name     string `db:"name"`
	Category string `db:"category"`
}

// exDB opens a private in-memory SQLite database and creates the ex_products
// table. Each call returns an independent database — no shared state between
// examples. Uses the plain sqlite driver directly (not the dbsqlx/sqlite
// adapter) to keep these examples focused on the driver-agnostic root API.
func exDB() *sqlx.DB {
	db, err := dbsqlx.Open("sqlite", ":memory:", nil)
	if err != nil {
		panic("exDB: " + err.Error())
	}
	if _, err := db.Exec(`CREATE TABLE ex_products (
		id INTEGER PRIMARY KEY AUTOINCREMENT,
		name TEXT NOT NULL,
		category TEXT NOT NULL DEFAULT ''
	)`); err != nil {
		panic("exDB create table: " + err.Error())
	}
	return db
}

func main() {
	ctx := context.Background()
	db := exDB()
	for i := range 5 {
		db.MustExec(`INSERT INTO ex_products (name) VALUES (?)`, fmt.Sprintf("item-%d", i))
	}

	para := dto.PageParameter{Page: 1, Limit: 3}
	query := "SELECT * FROM ex_products" + dbsqlx.PageSql(&para)

	var products []exProduct
	err := db.SelectContext(ctx, &products, query)
	fmt.Println(err == nil)
	fmt.Println(len(products)) // page 1, limit 3
}
Output:
true
3

func SetDefault

func SetDefault(db *sqlx.DB)

SetDefault replaces the process-wide default sqlx database instance.

Example

ExampleSetDefault shows how to store a *sqlx.DB as the process-wide default. Call SetDefault once at application startup after opening the database.

package main

import (
	"fmt"

	"github.com/phcp-tech/common-library-golang/dbsqlx"

	"github.com/vinovest/sqlx"
	_ "modernc.org/sqlite"
)

// exDB opens a private in-memory SQLite database and creates the ex_products
// table. Each call returns an independent database — no shared state between
// examples. Uses the plain sqlite driver directly (not the dbsqlx/sqlite
// adapter) to keep these examples focused on the driver-agnostic root API.
func exDB() *sqlx.DB {
	db, err := dbsqlx.Open("sqlite", ":memory:", nil)
	if err != nil {
		panic("exDB: " + err.Error())
	}
	if _, err := db.Exec(`CREATE TABLE ex_products (
		id INTEGER PRIMARY KEY AUTOINCREMENT,
		name TEXT NOT NULL,
		category TEXT NOT NULL DEFAULT ''
	)`); err != nil {
		panic("exDB create table: " + err.Error())
	}
	return db
}

func main() {
	prev := dbsqlx.Default()
	defer dbsqlx.SetDefault(prev) // restore after example

	dbsqlx.SetDefault(exDB())
	fmt.Println(dbsqlx.Default() != nil)
}
Output:
true

func SortSql

func SortSql(para *dto.PageParameter) string

SortSql builds an ORDER BY SQL clause from the sort fields in para. Defaults to ordering by "id ASC" when Sort is empty or unsafe.

SortSql only ever produces a plain "ORDER BY <column> <direction>" clause. It has no locale/charset-aware sorting, since that requires a database- specific SQL function (e.g. PostgreSQL's convert_to, MySQL's CONVERT(... USING ...)) that this dialect-agnostic root package cannot pick correctly on its own — callers needing that should build their own ORDER BY expression and append PageSql's LIMIT/OFFSET to it.

Example

ExampleSortSql shows how to build a safe ORDER BY clause from user-supplied sort parameters and append it directly to a raw SELECT statement.

package main

import (
	"context"
	"fmt"

	"github.com/phcp-tech/common-library-golang/dbsqlx"
	"github.com/phcp-tech/common-library-golang/dto"

	"github.com/vinovest/sqlx"
	_ "modernc.org/sqlite"
)

// exProduct is a minimal model used by the example functions.
type exProduct struct {
	ID       int64  `db:"id"`
	Name     string `db:"name"`
	Category string `db:"category"`
}

// exDB opens a private in-memory SQLite database and creates the ex_products
// table. Each call returns an independent database — no shared state between
// examples. Uses the plain sqlite driver directly (not the dbsqlx/sqlite
// adapter) to keep these examples focused on the driver-agnostic root API.
func exDB() *sqlx.DB {
	db, err := dbsqlx.Open("sqlite", ":memory:", nil)
	if err != nil {
		panic("exDB: " + err.Error())
	}
	if _, err := db.Exec(`CREATE TABLE ex_products (
		id INTEGER PRIMARY KEY AUTOINCREMENT,
		name TEXT NOT NULL,
		category TEXT NOT NULL DEFAULT ''
	)`); err != nil {
		panic("exDB create table: " + err.Error())
	}
	return db
}

func main() {
	ctx := context.Background()
	db := exDB()
	db.MustExec(`INSERT INTO ex_products (name) VALUES (?)`, "zebra")
	db.MustExec(`INSERT INTO ex_products (name) VALUES (?)`, "apple")

	para := dto.PageParameter{Sort: "name", Direction: "ASC"}
	query := "SELECT * FROM ex_products" + dbsqlx.SortSql(&para)

	var products []exProduct
	err := db.SelectContext(ctx, &products, query)
	fmt.Println(err == nil)
	fmt.Println(products[0].Name)
}
Output:
true
apple

func Transact

func Transact(ctx context.Context, db sqlx.Queryable, fn func(ctx context.Context, tx sqlx.Queryable) error) error

Transact runs fn inside a transaction on db, committing on success and rolling back on error or panic (the panic is recovered just long enough to roll back, then re-raised to the caller).

db must be *sqlx.DB for the outermost call. Nested calls made from inside fn — by passing the tx argument fn receives back into another Transact call with the same ctx — detect the ongoing transaction via ctx and reuse it instead of starting a new one; only the outermost call commits or rolls back.

Do not call Transact with a *sqlx.Tx obtained outside of this ctx-propagation mechanism (e.g. via db.Beginx()) as the outermost db argument: the library only begins a transaction when db is *sqlx.DB, so a bare *sqlx.Tx passed directly causes a nil-pointer panic on commit/rollback.

Example

ExampleTransact shows how to run several statements atomically. The callback receives tx (a sqlx.Queryable) instead of db — pass tx, not db, to every helper called inside the callback.

package main

import (
	"context"
	"fmt"

	"github.com/phcp-tech/common-library-golang/dbsqlx"

	"github.com/vinovest/sqlx"
	_ "modernc.org/sqlite"
)

// exDB opens a private in-memory SQLite database and creates the ex_products
// table. Each call returns an independent database — no shared state between
// examples. Uses the plain sqlite driver directly (not the dbsqlx/sqlite
// adapter) to keep these examples focused on the driver-agnostic root API.
func exDB() *sqlx.DB {
	db, err := dbsqlx.Open("sqlite", ":memory:", nil)
	if err != nil {
		panic("exDB: " + err.Error())
	}
	if _, err := db.Exec(`CREATE TABLE ex_products (
		id INTEGER PRIMARY KEY AUTOINCREMENT,
		name TEXT NOT NULL,
		category TEXT NOT NULL DEFAULT ''
	)`); err != nil {
		panic("exDB create table: " + err.Error())
	}
	return db
}

func main() {
	ctx := context.Background()
	db := exDB()

	err := dbsqlx.Transact(ctx, db, func(ctx context.Context, tx sqlx.Queryable) error {
		if _, err := dbsqlx.Exec(ctx, tx, `INSERT INTO ex_products (name) VALUES (?)`, "drill"); err != nil {
			return err
		}
		_, err := dbsqlx.Exec(ctx, tx, `INSERT INTO ex_products (name) VALUES (?)`, "sander")
		return err
	})
	fmt.Println(err == nil)

	var count int64
	_ = db.GetContext(ctx, &count, `SELECT COUNT(*) FROM ex_products`)
	fmt.Println(count)
}
Output:
true
2
Example (Rollback)

ExampleTransact_rollback shows that a non-nil error returned from the callback rolls back every statement executed inside the transaction.

package main

import (
	"context"
	"fmt"

	"github.com/phcp-tech/common-library-golang/dbsqlx"

	"github.com/vinovest/sqlx"
	_ "modernc.org/sqlite"
)

// exDB opens a private in-memory SQLite database and creates the ex_products
// table. Each call returns an independent database — no shared state between
// examples. Uses the plain sqlite driver directly (not the dbsqlx/sqlite
// adapter) to keep these examples focused on the driver-agnostic root API.
func exDB() *sqlx.DB {
	db, err := dbsqlx.Open("sqlite", ":memory:", nil)
	if err != nil {
		panic("exDB: " + err.Error())
	}
	if _, err := db.Exec(`CREATE TABLE ex_products (
		id INTEGER PRIMARY KEY AUTOINCREMENT,
		name TEXT NOT NULL,
		category TEXT NOT NULL DEFAULT ''
	)`); err != nil {
		panic("exDB create table: " + err.Error())
	}
	return db
}

func main() {
	ctx := context.Background()
	db := exDB()

	err := dbsqlx.Transact(ctx, db, func(ctx context.Context, tx sqlx.Queryable) error {
		if _, err := dbsqlx.Exec(ctx, tx, `INSERT INTO ex_products (name) VALUES (?)`, "temp"); err != nil {
			return err
		}
		return fmt.Errorf("something went wrong")
	})
	fmt.Println(err)

	var count int64
	_ = db.GetContext(ctx, &count, `SELECT COUNT(*) FROM ex_products`)
	fmt.Println(count) // 0 — the insert was rolled back
}
Output:
something went wrong
0

Types

type JSONRaw added in v0.1.32

type JSONRaw []byte

JSONRaw holds an arbitrary JSON value (object, array, string, ...) for a database column of type json/jsonb that's also exposed at a JSON API boundary (bound from a client request body, or marshaled into a response).

A plain []byte field is the wrong type for that: it round-trips correctly through a database column (sqlx binds/scans []byte directly), but encoding/json treats []byte specially — a []byte struct field marshals to a base64 string, and only unmarshals from one, not from a JSON object. A client sending a normal JSON object for that field fails with "json: cannot unmarshal object into Go struct field ... of type []uint8"; a server returning one instead returns a meaningless base64 string that silently isn't the JSON object callers expect.

JSONRaw fixes both directions: MarshalJSON/UnmarshalJSON pass the bytes through untouched, so a JSON object stays a JSON object on the wire, both into and out of the API — while Scan/Value make it bind/scan against a json/jsonb database column exactly like []byte already did.

It also closes a second, sharper edge: a caller that never touches the field ends up with a nil JSONRaw, but a client that explicitly POSTs `"data": ""` for a []byte field decodes (via base64) to a non-nil, empty slice — indistinguishable from "no data" by intent, but not by a `== nil` guard. Passed straight through to an INSERT/UPDATE, an empty (but non-nil) value is bound as an empty string, which every Postgres json/jsonb column rejects as invalid input: "invalid input syntax for type json" (SQLSTATE 22P02). JSONRaw's Value() treats any zero-length value as SQL NULL instead, so this can't happen regardless of whether the call site remembered to guard against it.

Deliberately not encoding/json.RawMessage: some of this library's consumers build with GOEXPERIMENT=jsonv2, under which RawMessage no longer satisfies database/sql's generic []byte-scan fallback — Scan then errors ("unsupported Scan ... into type *jsontext.Value") for both NULL and non-NULL driver values. JSONRaw sidesteps that fallback entirely by implementing sql.Scanner/driver.Valuer itself.

Also deliberately not gorm.io/datatypes.JSON, which already solves the same three problems: reusing it would pull the entire GORM module into every consumer of this package, including the sqlx-only, no-ORM services that migrated away from GORM specifically to avoid that dependency.

func (JSONRaw) MarshalJSON added in v0.1.32

func (j JSONRaw) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler, emitting the held bytes as-is — callers marshaling a struct with a JSONRaw field get the field back as a real JSON value, not a base64 string. An empty/nil JSONRaw marshals to the JSON literal null (mirrors encoding/json.RawMessage's own behavior).

func (*JSONRaw) Scan added in v0.1.32

func (j *JSONRaw) Scan(src any) error

Scan implements sql.Scanner. A SQL NULL becomes a nil JSONRaw rather than an error — the same "no data set" state a genuinely absent value has.

func (*JSONRaw) UnmarshalJSON added in v0.1.32

func (j *JSONRaw) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler, storing data as-is — a JSON object/array in the request body lands in the field verbatim, with no base64 decoding step required (or accepted) from the caller.

func (JSONRaw) Value added in v0.1.32

func (j JSONRaw) Value() (driver.Value, error)

Value implements driver.Valuer. A zero-length JSONRaw becomes SQL NULL rather than an empty string — see the type doc comment for why this matters: an empty string is not valid input for a json/jsonb column.

type PoolConfig

type PoolConfig struct {
	MaxOpenConns    int
	MaxIdleConns    int
	ConnMaxLifetime int // minutes
	ConnMaxIdletime int // minutes
}

PoolConfig contains connection-pool tuning parameters shared by all dbsqlx adapters. Zero-value fields fall back to the package-level defaults above.

Directories

Path Synopsis
component
Package component provides sqlx ClickHouse lifecycle integration for bootstrap.
Package component provides sqlx ClickHouse lifecycle integration for bootstrap.
Package clickhousenative provides a ClickHouse client using the native TCP protocol via github.com/ClickHouse/clickhouse-go/v2.
Package clickhousenative provides a ClickHouse client using the native TCP protocol via github.com/ClickHouse/clickhouse-go/v2.
component
Package component provides ClickHouse native-driver lifecycle integration for bootstrap.
Package component provides ClickHouse native-driver lifecycle integration for bootstrap.
component
Package component provides sqlx MySQL lifecycle integration for bootstrap.
Package component provides sqlx MySQL lifecycle integration for bootstrap.
component
Package component provides sqlx PostgreSQL lifecycle integration for bootstrap.
Package component provides sqlx PostgreSQL lifecycle integration for bootstrap.
component
Package component provides sqlx SQLite lifecycle integration for bootstrap.
Package component provides sqlx SQLite lifecycle integration for bootstrap.
vfs
Package vfs opens a SQLite database embedded inside a Go binary using modernc.org/sqlite/vfs and Go's embed.FS.
Package vfs opens a SQLite database embedded inside a Go binary using modernc.org/sqlite/vfs and Go's embed.FS.

Jump to

Keyboard shortcuts

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