xql

package module
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2021 License: Apache-2.0 Imports: 8 Imported by: 2

README

go.xql, another ORM for golang

To be done.

See example

Documentation

Index

Constants

View Source
const (
	ConstraintNone uint8 = iota
	ConstraintCheck
	ConstraintNotNull
	ConstraintUnique
	ConstraintPrimaryKey
	ConstraintForeignKey
	ConstraintExclude
	ConstraintInvalid
)
View Source
const (
	IndexNone uint8 = iota
	IndexBTree
	IndexHash
	IndexGist
	IndexSpGist
	IndexGin
	IndexBrin
	IndexInvalid
)

PostgreSQL provides several index types: B-tree, Hash, GiST, SP-GiST, GIN and BRIN

View Source
const (
	SingleQuoteOpened uint = 0x01
	DoubleQuoteOpened uint = 0x02
	SBraceOpened      uint = 0x04
	MBraceOpened      uint = 0x08
	BBraceOpened      uint = 0x10
)

Variables

This section is empty.

Functions

func Camel2Underscore

func Camel2Underscore(s string) string

func DefaultDeclare added in v0.2.1

func DefaultDeclare(f reflect.StructField, props PropertySet) (string, error)

func ParseDottedArgs added in v0.5.1

func ParseDottedArgs(s string) (ret []string)

func RegisterDialect

func RegisterDialect(name string, d IDialect)

Types

type BigInteger added in v0.2.1

type BigInteger int64

bigint 8 bytes large-range integer -9223372036854775808 to +9223372036854775807

func (BigInteger) Declare added in v0.2.1

func (s BigInteger) Declare(props PropertySet) string

type BigSerial added in v0.2.1

type BigSerial uint64

bigserial 8 bytes large autoincrementing integer 1 to 9223372036854775807

func (BigSerial) Declare added in v0.2.1

func (s BigSerial) Declare(props PropertySet) string

type Bit added in v0.2.1

type Bit string

func (Bit) Declare added in v0.2.1

func (b Bit) Declare(props PropertySet) string

type Bitvar added in v0.2.1

type Bitvar string

func (Bitvar) Declare added in v0.2.1

func (b Bitvar) Declare(props PropertySet) string

type Boolean added in v0.2.1

type Boolean bool

Boolean Data Type

Name Storage Size Description boolean 1 byte state of true or false

func (Boolean) Declare added in v0.2.1

func (s Boolean) Declare(props PropertySet) string

type Bytea added in v0.2.1

type Bytea []byte

Binary Data Types

Name Storage Size Description bytea 1 or 4 bytes plus the actual binary string variable-length binary string

func (Bytea) Declare added in v0.2.1

func (b Bytea) Declare(props PropertySet) string

type Char added in v0.2.1

type Char string

character(n), char(n) fixed-length, blank padded

func (Char) Declare added in v0.2.1

func (s Char) Declare(props PropertySet) string

type Column

type Column struct {
	PropertySet
	FieldName   string
	ElemName    string
	JTag        string
	Type        reflect.Type
	TypeDefine  string
	Indexed     bool // Indexed or not, on field
	Nullable    bool // Nullable constraint on field
	Unique      bool // Unique constraint on field
	PrimaryKey  bool //Primary Key constraint on field
	Default     interface{}
	Constraints []*Constraint
	Indexes     []*Index
	// contains filtered or unexported fields
}

type ConditionType

type ConditionType uint
const (
	ConditionAnd ConditionType = iota
	ConditionOr
)

type Constraint added in v0.2.1

type Constraint struct {
	Type      uint8
	Columns   []*Column
	Refernces []*Column
	Statement string
	OnDelete  string
	OnUpdate  string
}

type Date added in v0.2.1

type Date time.Time

date 4 bytes date (no time of day) 4713 BC 5874897 AD 1 day

func (Date) Declare added in v0.2.1

func (s Date) Declare(props PropertySet) string

type Decimal added in v0.2.1

type Decimal string

decimal variable user-specified precision, exact up to 131072 digits before the decimal point; up to 16383 digits after the decimal point

func (Decimal) Declare added in v0.2.1

func (d Decimal) Declare(props PropertySet) string

type Declarable added in v0.2.1

type Declarable interface {
	Declare(props PropertySet) string
}

type Double added in v0.2.1

type Double float64

double precision 8 bytes variable-precision, inexact 15 decimal digits precision

func (Double) Declare added in v0.2.1

func (s Double) Declare(props PropertySet) string

type Engine

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

func CreateEngine

func CreateEngine(name string, dataSource string) (*Engine, error)

func (Engine) DB added in v0.2.11

func (engine Engine) DB() *sql.DB

func (Engine) DriverName added in v0.2.11

func (engine Engine) DriverName() string

func (*Engine) MakeSession

func (engine *Engine) MakeSession() *Session

type Enum added in v0.2.1

type Enum string

CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');

func (Enum) Declare added in v0.2.1

func (s Enum) Declare(props PropertySet) string

type IDialect

type IDialect interface {
	Create(*Table, ...interface{}) (string, []interface{}, error)
	Drop(*Table, bool) (string, []interface{}, error)
	Select(*Table, []QueryColumn, []QueryFilter, []QueryOrder, string, int64, int64) (string, []interface{}, error)
	Insert(*Table, interface{}, ...string) (string, []interface{}, error)
	InsertWithInsertedId(*Table, interface{}, string, ...string) (string, []interface{}, error)
	Update(*Table, []QueryFilter, ...UpdateColumn) (string, []interface{}, error)
	Delete(*Table, []QueryFilter) (string, []interface{}, error)
}

type Index added in v0.2.1

type Index struct {
	Type    uint8
	Name    string
	Columns []*Column
}

type Integer added in v0.2.1

type Integer int

integer 4 bytes typical choice for integer -2147483648 to +2147483647

func (Integer) Declare added in v0.2.1

func (s Integer) Declare(props PropertySet) string

type Interval added in v0.2.1

type Interval time.Duration

interval [ columns ] [ (p) ] 16 bytes time interval -178000000 years 178000000 years 1 microsecond / 14 digits

func (Interval) Declare added in v0.2.1

func (s Interval) Declare(props PropertySet) string

type Numeric added in v0.2.1

type Numeric Decimal

numeric variable user-specified precision, exact up to 131072 digits before the decimal point; up to 16383 digits after the decimal point

type OrderType

type OrderType uint
const (
	OrderAsc OrderType = iota
	OrderDesc
)

type PropertySet added in v0.2.1

type PropertySet map[string]string

func ParseProperties added in v0.2.1

func ParseProperties(s string) (PropertySet, error)

func (PropertySet) GetBool added in v0.2.1

func (h PropertySet) GetBool(k string, defaults ...bool) (bool, bool)

func (PropertySet) GetInt added in v0.2.1

func (h PropertySet) GetInt(k string, defaults ...int) (int, bool)

func (PropertySet) GetInt64 added in v0.2.1

func (h PropertySet) GetInt64(k string, defaults ...int64) (int64, bool)

func (PropertySet) GetString added in v0.2.1

func (h PropertySet) GetString(k string, defaults ...string) (string, bool)

func (PropertySet) GetUInt added in v0.2.1

func (h PropertySet) GetUInt(k string, defaults ...uint) (uint, bool)

func (PropertySet) HasKey added in v0.2.1

func (h PropertySet) HasKey(k string) bool

func (PropertySet) PopBool added in v0.2.1

func (h PropertySet) PopBool(k string, defaults ...bool) (bool, bool)

func (PropertySet) PopInt added in v0.2.1

func (h PropertySet) PopInt(k string, defaults ...int) (int, bool)

func (PropertySet) PopInt64 added in v0.2.1

func (h PropertySet) PopInt64(k string, defaults ...int64) (int64, bool)

func (PropertySet) PopString added in v0.2.1

func (h PropertySet) PopString(k string, defaults ...string) (string, bool)

func (PropertySet) PopUInt added in v0.2.1

func (h PropertySet) PopUInt(k string, defaults ...uint) (uint, bool)

type QueryColumn

type QueryColumn struct {
	FieldName string
	Function  string
	Alias     string
}

func (QueryColumn) String

func (qc QueryColumn) String(as ...bool) string

type QueryExtra added in v0.4.8

type QueryExtra map[string]interface{}

type QueryFilter

type QueryFilter struct {
	Condition ConditionType // AND , OR
	Reversed  bool          // Reversed Column and Value if it is true
	Field     string
	Operator  string // Value will not used if empty.
	Function  string
	Value     interface{}
}

func Where added in v0.3.1

func Where(field string, val interface{}, ops ...string) QueryFilter

type QueryOrder

type QueryOrder struct {
	Type  OrderType
	Field string
}

type QuerySet

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

func (QuerySet) All

func (qs QuerySet) All() (*XRows, error)

func (QuerySet) And added in v0.3.1

func (qs QuerySet) And(field string, val interface{}, ops ...string) QuerySet

func (QuerySet) Count

func (qs QuerySet) Count(cols ...string) (int64, error)

func (QuerySet) Delete

func (qs QuerySet) Delete() (int64, error)

func (QuerySet) Filter

func (qs QuerySet) Filter(cons ...interface{}) QuerySet

func (QuerySet) Get added in v0.2.4

func (qs QuerySet) Get(pks ...interface{}) *XRow

func (QuerySet) Insert

func (qs QuerySet) Insert(objs ...interface{}) (int64, error)

func (QuerySet) InsertWithInsertedId added in v0.2.11

func (qs QuerySet) InsertWithInsertedId(obj interface{}, idname string, id interface{}) error

func (QuerySet) Limit

func (qs QuerySet) Limit(limit int64) QuerySet

func (QuerySet) LockFor added in v0.4.8

func (qs QuerySet) LockFor(s string) QuerySet

func (QuerySet) Offset

func (qs QuerySet) Offset(offset int64) QuerySet

func (QuerySet) One

func (qs QuerySet) One() *XRow

func (QuerySet) Or added in v0.3.1

func (qs QuerySet) Or(field string, val interface{}, ops ...string) QuerySet

func (QuerySet) OrderBy

func (qs QuerySet) OrderBy(orders ...interface{}) QuerySet

func (QuerySet) Update

func (qs QuerySet) Update(vals interface{}) (int64, error)

func (QuerySet) Where added in v0.3.1

func (qs QuerySet) Where(field string, val interface{}, ops ...string) QuerySet

type Real added in v0.2.1

type Real float32

real 4 bytes variable-precision, inexact 6 decimal digits precision

func (Real) Declare added in v0.2.1

func (s Real) Declare(props PropertySet) string

type Serial added in v0.2.1

type Serial uint

serial 4 bytes autoincrementing integer 1 to 2147483647

func (Serial) Declare added in v0.2.1

func (s Serial) Declare(props PropertySet) string

type Session

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

func MakeSession

func MakeSession(db *sql.DB, driverName string, verbose ...bool) *Session

func (*Session) Begin

func (session *Session) Begin() error

func (*Session) Close

func (session *Session) Close()

func (*Session) Commit

func (session *Session) Commit() error

func (*Session) Create

func (session *Session) Create(table *Table) error

func (*Session) Drop added in v0.2.1

func (session *Session) Drop(table *Table, force bool) error

func (*Session) Exec

func (session *Session) Exec(query string, args ...interface{}) (sql.Result, error)

func (*Session) Query

func (session *Session) Query(query string, args ...interface{}) (*sql.Rows, error)

func (*Session) QueryRow added in v0.4.1

func (session *Session) QueryRow(query string, args ...interface{}) *sql.Row

func (*Session) Rollback

func (session *Session) Rollback() error

func (*Session) Table added in v0.4.1

func (session *Session) Table(table *Table, columns ...interface{}) QuerySet

type SmallInteger added in v0.2.1

type SmallInteger int16

Name Storage Size Description Range type TinyInteger int8

func (s TinyInteger) Declare(props PropertySet) string {
   return "TINYINT"
}

smallint 2 bytes small-range integer -32768 to +32767

func (SmallInteger) Declare added in v0.2.1

func (s SmallInteger) Declare(props PropertySet) string

type SmallSerial added in v0.2.1

type SmallSerial uint16

type TinySerial uint8

func (s TinySerial) Declare(props PropertySet) string {
   return "TINYSERIAL"
}

smallserial 2 bytes small autoincrementing integer 1 to 32767

func (SmallSerial) Declare added in v0.2.1

func (s SmallSerial) Declare(props PropertySet) string

type Table

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

Table ... Struct defined for a table object.

func DeclareTable

func DeclareTable(entity TableIdentified, schema ...string) *Table

DeclareTable Which declare a new Table instance according to a given entity.

func (*Table) BaseTableName added in v0.2.1

func (t *Table) BaseTableName() string

func (*Table) GetColumn

func (t *Table) GetColumn(name string) (*Column, bool)

func (*Table) GetColumns added in v0.2.1

func (t *Table) GetColumns() []*Column

func (*Table) GetConstraints added in v0.2.1

func (t *Table) GetConstraints() []*Constraint

func (*Table) GetIndexes added in v0.2.1

func (t *Table) GetIndexes() []*Index

func (*Table) GetPrimaryKeys added in v0.2.2

func (t *Table) GetPrimaryKeys() []*Column

func (*Table) Schema

func (t *Table) Schema() string

func (*Table) SetSchema added in v0.2.2

func (t *Table) SetSchema(s string)

func (*Table) TableName

func (t *Table) TableName() string

type TableConstrained added in v0.5.1

type TableConstrained interface {
	Constraints() [][3]string
}

TableConstrained Which allow struct to define a method Constraints() to customize table constraints type, fields, statement

type TableCreatable added in v0.2.14

type TableCreatable interface {
	Creatable() bool
}

type TableDeletable added in v0.2.14

type TableDeletable interface {
	Deletable() bool
}

type TableIdentified added in v0.2.1

type TableIdentified interface {
	TableName() string
}

TableIdentified which make sure struct have a method TableName() This is mandatory for a struct can use as Table structure.

type TableIgnored added in v0.2.1

type TableIgnored interface {
	Ignore() []string
}

TableIgnored Which allow struct to define a method Ignore() to tell ignore elements for table columns

type TableIndexed added in v0.2.1

type TableIndexed interface {
	Indexes() [][2]string
}

TableIndexed Which allow struct to define a method Indexes() to define table indexes type, fields, statement

type TablePostDelete added in v0.2.1

type TablePostDelete interface {
	PostDelete(*Table, *Session) error
}

type TablePostInsert added in v0.2.1

type TablePostInsert interface {
	PostInsert(*Table, *Session) error
}

type TablePostUpdate added in v0.2.1

type TablePostUpdate interface {
	PostUpdate(*Table, *Session) error
}

type TablePreDelete added in v0.2.1

type TablePreDelete interface {
	PreDelete(*Table, *Session) error
}

type TablePreInsert added in v0.2.1

type TablePreInsert interface {
	PreInsert(*Table, *Session) error
}

TablePreInsert Which entity implemented will be called when xql create a new struct instance.

type TablePreUpdate added in v0.2.6

type TablePreUpdate interface {
	PreUpdate(*Table, *Session) error
}

type TableReadable added in v0.2.14

type TableReadable interface {
	Readable() bool
}

type TableUpdatable added in v0.2.14

type TableUpdatable interface {
	Updatable() bool
}

type Text added in v0.2.1

type Text string

text variable unlimited length

func (Text) Declare added in v0.2.1

func (s Text) Declare(props PropertySet) string

type Time added in v0.2.1

type Time time.Time

time [ (p) ] [ without time zone ] 8 bytes time of day (no date) 00:00:00 24:00:00 1 microsecond / 14 digits time [ (p) ] with time zone 12 bytes times of day only, with time zone 00:00:00+1459 24:00:00-1459 1 microsecond / 14 digits

func (Time) Declare added in v0.2.1

func (s Time) Declare(props PropertySet) string

type TimeStamp added in v0.2.1

type TimeStamp time.Time

Date/Time Types

Name Storage Size Description Low Value High Value Resolution timestamp [ (p) ] [ without time zone ] 8 bytes both date and time (no time zone) 4713 BC 294276 AD 1 microsecond / 14 digits timestamp [ (p) ] with time zone 8 bytes both date and time, with time zone 4713 BC 294276 AD 1 microsecond / 14 digits

func (TimeStamp) Declare added in v0.2.1

func (s TimeStamp) Declare(props PropertySet) string

type UUID added in v0.2.1

type UUID string

UUID Type

func (UUID) Declare added in v0.2.1

func (s UUID) Declare(props PropertySet) string

type UpdateColumn

type UpdateColumn struct {
	Field    string
	Operator string
	Value    interface{}
}

type Varchar added in v0.2.1

type Varchar string

Name Description character varying(n), varchar(n) variable-length with limit

func (Varchar) Declare added in v0.2.1

func (s Varchar) Declare(props PropertySet) string

type XRow

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

func (*XRow) Scan

func (xr *XRow) Scan(dest ...interface{}) error

type XRows

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

func (*XRows) Close

func (xr *XRows) Close()

func (*XRows) Next

func (xr *XRows) Next() bool

func (*XRows) Scan

func (xr *XRows) Scan(dest ...interface{}) error

Directories

Path Synopsis
dialects

Jump to

Keyboard shortcuts

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