sqldialect

package
v0.65.1 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: 3 Imported by: 0

Documentation

Overview

Package sqldialect centralizes SQL-dialect literals shared by metadata query packages. Keeping one implementation prevents a corrected or newly added backend from silently leaving account-history queries inconsistent with stake queries. Every helper is pure and treats a nil db the same as sqlite.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArithmeticParam added in v0.65.0

func ArithmeticParam(db *gorm.DB) string

ArithmeticParam returns the bind fragment for a types.Uint64 operand used directly in arithmetic. MySQL and Postgres require an explicit numeric cast so a bound decimal string never promotes the expression to floating point.

func BoolLiteral added in v0.65.0

func BoolLiteral(db *gorm.DB, value bool) string

BoolLiteral renders a boolean literal for raw SQL.

func IntegerCastType

func IntegerCastType(db *gorm.DB) string

IntegerCastType returns the backend-native integer type used to CAST the text-encoded (types.Uint64) columns before arithmetic or numeric comparison. The utxo.amount and account.reward columns used by the metadata stake and voting-power queries are stored as decimal-string TEXT (see types.Uint64.Value) regardless of backend, so any SUM, arithmetic, or ordering comparison touching them must cast first: sqlite is loosely typed and tolerates INTEGER; mysql needs UNSIGNED to preserve values above math.MaxInt64 exactly (a signed cast would overflow); postgres needs NUMERIC and, unlike sqlite/mysql, never implicitly coerces TEXT to a numeric type, so postgres queries fail outright without the cast.

func Name

func Name(db *gorm.DB) string

Name returns the lower-cased dialect name for db, or "" for a nil db (treated the same as sqlite by every helper below).

func TextCastType added in v0.65.0

func TextCastType(db *gorm.DB) string

TextCastType returns the CAST target for the decimal-string representation stored in types.Uint64 columns.

func TransactionTableName

func TransactionTableName(db *gorm.DB) string

TransactionTableName returns the quoted reference to the "transaction" table for the backend dialect of db. mysql does not require quoting here (TRANSACTION is not a reserved word), but backtick-quoting it is always valid there; postgres and sqlite both require double quotes because "transaction" collides with the SQL TRANSACTION keyword in unquoted position.

Types

This section is empty.

Jump to

Keyboard shortcuts

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