sqlbuilder

package
v0.0.0-...-16263d3 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SqlTagDefault = "sql"
)

Tag prefixes

Variables

This section is empty.

Functions

This section is empty.

Types

type SqlBuilder

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

SqlBuilder ...

func NewSqlBuilder

func NewSqlBuilder(opts ...SqlBuilderOption) *SqlBuilder

NewSqlBuilder ...

func (SqlBuilder) AddTable

func (s SqlBuilder) AddTable(obj interface{}) string

AddTable ...

func (SqlBuilder) GetTableName

func (s SqlBuilder) GetTableName(t interface{}) (string, string)

GetTableName read from TableNameFn or parse table name from model as snake_case return object name and table name

func (*SqlBuilder) MappingTables

func (s *SqlBuilder) MappingTables(m map[string]string)

MappingTables ...

func (SqlBuilder) RemoveTable

func (s SqlBuilder) RemoveTable(tb interface{}) string

RemoveTable ...

type SqlBuilderOption

type SqlBuilderOption interface {
	// contains filtered or unexported methods
}

SqlBuilderOption ...

func WithCommentGenerate

func WithCommentGenerate() SqlBuilderOption

WithCommentGenerate default is off

func WithDialect

func WithDialect(dialect sqltemplates.SqlDialect) SqlBuilderOption

WithDialect ...

func WithMysql

func WithMysql() SqlBuilderOption

WithMysql default

func WithPluralTableName

func WithPluralTableName() SqlBuilderOption

WithPluralTableName Table name in plural convention - ending with `s`

func WithPointerAsValue

func WithPointerAsValue() SqlBuilderOption

WithPointerAsValue maps pointer fields by their pointed-to value type rather than emitting "POINTER", so *time.Time becomes TEXT (ISO8601), *string TEXT, *int INTEGER and so on, even when the pointer is nil. Pointers to structs other than time.Time (e.g. *gofeed.Person, *gofeed.Image) are stored as JSON TEXT columns.

func WithPostgresql

func WithPostgresql() SqlBuilderOption

WithPostgresql ...

func WithSliceAsJson

func WithSliceAsJson() SqlBuilderOption

WithSliceAsJson stores slice and map fields as a JSON blob in a TEXT column instead of emitting the opaque "UNSPECIFIED" type. For structs like gofeed this turns Categories []string, Links []string, Custom map[string]string, Authors []*Person etc. into queryable SQLite json1 TEXT columns. A per-field `json` tag directive, when present, still takes precedence.

func WithSqlLowercase

func WithSqlLowercase() SqlBuilderOption

WithSqlLowercase ...

func WithSqlTag

func WithSqlTag(sqlTag string) SqlBuilderOption

WithSqlTag default tag is `sql`

func WithSqlUppercase

func WithSqlUppercase() SqlBuilderOption

WithSqlUppercase default

func WithSqlite

func WithSqlite() SqlBuilderOption

WithSqlite ...

func WithSqlserver

func WithSqlserver() SqlBuilderOption

WithSqlserver ...

func WithTagNameAsColumn

func WithTagNameAsColumn() SqlBuilderOption

WithTagNameAsColumn uses the first value of the tag (the text before the first comma, as read by encoding/json and sqlx) as the column name instead of the snake-cased Go field name. This lets structs carrying only `json` tag names (e.g. gofeed) round-trip with sqlx's reflectx.NewMapper("json"). A `column:` directive in the tag still overrides the name when present.

Jump to

Keyboard shortcuts

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