gosql

package module
v0.0.10 Latest Latest
Warning

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

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

README

GoSQL

This isn't anything serious, just a little bit of code I'd like to re-use for generating basic SQL statements.

Depends on: github.com/mattn/go-sqlite3

Documentation

Index

Constants

View Source
const (
	ConditionEquals              = "="
	ConditionNotEquals           = "<>"
	ConditionLessThan            = "<"
	ConditionGreaterThan         = ">"
	ConditionLessThanOrEquals    = "<="
	ConditionGreaterThanOrEquals = ">="
	ConditionLike                = "LIKE"
	ConditionNotLike             = "NOT LIKE"
	ConditionIn                  = "IN"
	ConditionNotIn               = "NOT IN"
	ConditionBetween             = "BETWEEN"
	ConditionNotBetween          = "NOT BETWEEN"
	ConditionIsNull              = "IS NULL"
	ConditionIsNotNull           = "IS NOT NULL"

	ConjunctionAnd = "AND"
	ConjunctionOr  = "OR"
)
View Source
const (
	ActionSelect = "SELECT"
	ActionInsert = "INSERT"
	ActionUpdate = "UPDATE"
	ActionDelete = "DELETE"

	OrderDirectionAscending  = "ASC"
	OrderDirectionDescending = "DESC"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Constraint

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

type Constraints

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

func (*Constraints) And

func (c *Constraints) And(field, condition string, value any) *Constraints

func (*Constraints) Or

func (c *Constraints) Or(field, condition string, value any) *Constraints

type Join

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

func (*Join) On

func (j *Join) On(leftField, rightField string)

type Query

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

func Delete

func Delete() *Query

func Insert

func Insert() *Query

func Raw added in v0.0.4

func Raw(sql string) *Query

func Select

func Select() *Query

func Update

func Update() *Query

func (*Query) AlsoFrom

func (q *Query) AlsoFrom(name, conjunction string) *Table

func (*Query) Build

func (q *Query) Build() (string, []any)

func (*Query) Distinct added in v0.0.6

func (q *Query) Distinct() *Query

func (*Query) From

func (q *Query) From(name string) *Table

func (Query) HasConstraints

func (q Query) HasConstraints() bool

func (*Query) Ignore added in v0.0.5

func (q *Query) Ignore() *Query

func (Query) IsJoin added in v0.0.8

func (q Query) IsJoin(tableName string) bool

func (*Query) Join

func (q *Query) Join(leftTable, rightTable string) *Join

func (*Query) Limit added in v0.0.5

func (q *Query) Limit(limit, offset int) *Query

func (*Query) OrderAscending added in v0.0.5

func (q *Query) OrderAscending(field string) *Query

func (*Query) OrderDescending added in v0.0.5

func (q *Query) OrderDescending(field string) *Query

func (*Query) Table

func (q *Query) Table(name string) *Table

func (*Query) To

func (q *Query) To(name string) *Table

type SQLDB

type SQLDB interface {
	IsOpen() bool
	Open() error
	Close() error
	Query(Query) (*sql.Rows, error)
	Exec(Query) (sql.Result, error)
}

type SQLite

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

func NewSQLite

func NewSQLite(path string) SQLite

func (*SQLite) Close

func (db *SQLite) Close() error

func (*SQLite) Conn added in v0.0.10

func (db *SQLite) Conn() *sql.DB

func (SQLite) Exec

func (db SQLite) Exec(query *Query) (sql.Result, error)

func (SQLite) IsOpen

func (db SQLite) IsOpen() bool

func (*SQLite) Open

func (db *SQLite) Open() error

func (SQLite) Query

func (db SQLite) Query(query *Query) (*sql.Rows, error)

type Table

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

func (*Table) AndWhere added in v0.0.9

func (t *Table) AndWhere(field, condition string, value any) *Constraints

func (*Table) Fields

func (t *Table) Fields(fields ...string) *Table

func (Table) HasField

func (t Table) HasField(name string) bool

func (*Table) OrWhere added in v0.0.9

func (t *Table) OrWhere(field, condition string, value any) *Constraints

func (*Table) Set

func (t *Table) Set(field string, value any) *Table

func (*Table) Values

func (t *Table) Values(values ...any) *Table

func (*Table) Where

func (t *Table) Where(field, condition string, value any) *Constraints

Jump to

Keyboard shortcuts

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