xsql

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package xsql extends for the sql package. power by <Joshua Conero>(2020)

Package xsql extends for the sql package. power by <Joshua Conero>(2020)

Index

Constants

View Source
const (
	Version     = "0.1.0"
	Release     = "dev"
	Description = "concise and lightweight SQL builder."
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

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

Builder need to do. the sql builder

func Table

func Table(table any, alias ...string) *Builder

Table Table(string/string interface) Table([]string{name, alias})

func (*Builder) Columns

func (c *Builder) Columns(columns ...string) *Builder

func (*Builder) Delete

func (c *Builder) Delete() *Builder

func (*Builder) GetSQL

func (c *Builder) GetSQL() (string, []any)

GetSQL only get SQL where exist sql if not will call SQL builder

func (*Builder) GetTableString

func (c *Builder) GetTableString() string

func (*Builder) GroupBy

func (c *Builder) GroupBy(groupBys ...string) *Builder

GroupBy call once, then more to reset.

func (*Builder) InnerJoin

func (c *Builder) InnerJoin(table, cond string) *Builder

func (*Builder) Insert

func (c *Builder) Insert(data map[string]any) *Builder

func (*Builder) Join

func (c *Builder) Join(table, cond, vtype string) *Builder

func (*Builder) LeftJoin

func (c *Builder) LeftJoin(table, cond string) *Builder

func (*Builder) Limit

func (c *Builder) Limit(offset int, orRowCount ...int) *Builder

func (*Builder) OrderBy

func (c *Builder) OrderBy(orderBys ...string) *Builder

OrderBy call once, then more to reset.

func (*Builder) Page

func (c *Builder) Page(page int, orPageSize ...int) *Builder

func (*Builder) ResetBinds

func (c *Builder) ResetBinds() *Builder

func (*Builder) ResetWhere

func (c *Builder) ResetWhere(where string, binds ...any) *Builder

func (*Builder) RightJoin

func (c *Builder) RightJoin(table, cond string) *Builder

func (*Builder) Select

func (c *Builder) Select(columns ...string) *Builder

func (*Builder) ToSQL

func (c *Builder) ToSQL() (string, []any)

ToSQL build SQL every time

func (*Builder) Update

func (c *Builder) Update(data map[string]any) *Builder

func (*Builder) Where

func (c *Builder) Where(where string, binds ...any) *Builder

type Config added in v1.1.1

type Config struct {
	TablePrefix string
	DbType      string
}

type Query

type Query struct {
	DB       *sql.DB
	RowCount int //the count query result lines.
}

func NewQuery

func NewQuery(db *sql.DB) *Query

func (*Query) RowsDick

func (c *Query) RowsDick(rows *sql.Rows) ([]map[string]any, error)

RowsDick reference link: https://blog.csdn.net/weimingjue/article/details/91042649 get the rows dick database map to golang type:

INT    							int64
SMALLINT,TINYINT    			int
DECIMAL    						float64
DATETIME,DATE    				time.Time; <!temp make to string>
VARCHAR,CHAR,TEXT				string

func (*Query) Select

func (c *Query) Select(query string, args ...any) ([]map[string]any, error)

type Xsql added in v1.1.1

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

func NewXsql added in v1.1.1

func NewXsql(conn *sql.DB, cfgs ...Config) *Xsql

func (*Xsql) Name added in v1.1.1

func (x *Xsql) Name(tb string, alias ...string) *Builder

func (*Xsql) SelectFunc added in v1.1.1

func (x *Xsql) SelectFunc(call func(*Builder), tb string, alias ...string) ([]map[string]any, error)

Jump to

Keyboard shortcuts

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