xorm: xorm.io/xorm/schemas Index | Files

package schemas

import "xorm.io/xorm/schemas"

Index

Package Files

column.go index.go pk.go quote.go table.go type.go

Constants

const (
    TWOSIDES = iota + 1
    ONLYTODB
    ONLYFROMDB
)
const (
    IndexType = iota + 1
    UniqueType
)

enumerate all index types

const (
    UNKNOW_TYPE = iota
    TEXT_TYPE
    BLOB_TYPE
    TIME_TYPE
    NUMERIC_TYPE
    ARRAY_TYPE
)

Variables

var (
    // AlwaysFalseReverse always think it's not a reverse word
    AlwaysNoReserve = func(string) bool { return false }

    // AlwaysReverse always reverse the word
    AlwaysReserve = func(string) bool { return true }

    // CommanQuoteMark represnets the common quote mark
    CommanQuoteMark byte = '`'

    // CommonQuoter represetns a common quoter
    CommonQuoter = Quoter{CommanQuoteMark, CommanQuoteMark, AlwaysReserve}
)
var (
    Bit       = "BIT"
    TinyInt   = "TINYINT"
    SmallInt  = "SMALLINT"
    MediumInt = "MEDIUMINT"
    Int       = "INT"
    Integer   = "INTEGER"
    BigInt    = "BIGINT"

    Enum = "ENUM"
    Set  = "SET"

    Char             = "CHAR"
    Varchar          = "VARCHAR"
    NChar            = "NCHAR"
    NVarchar         = "NVARCHAR"
    TinyText         = "TINYTEXT"
    Text             = "TEXT"
    NText            = "NTEXT"
    Clob             = "CLOB"
    MediumText       = "MEDIUMTEXT"
    LongText         = "LONGTEXT"
    Uuid             = "UUID"
    UniqueIdentifier = "UNIQUEIDENTIFIER"
    SysName          = "SYSNAME"

    Date          = "DATE"
    DateTime      = "DATETIME"
    SmallDateTime = "SMALLDATETIME"
    Time          = "TIME"
    TimeStamp     = "TIMESTAMP"
    TimeStampz    = "TIMESTAMPZ"
    Year          = "YEAR"

    Decimal    = "DECIMAL"
    Numeric    = "NUMERIC"
    Money      = "MONEY"
    SmallMoney = "SMALLMONEY"

    Real   = "REAL"
    Float  = "FLOAT"
    Double = "DOUBLE"

    Binary     = "BINARY"
    VarBinary  = "VARBINARY"
    TinyBlob   = "TINYBLOB"
    Blob       = "BLOB"
    MediumBlob = "MEDIUMBLOB"
    LongBlob   = "LONGBLOB"
    Bytea      = "BYTEA"

    Bool    = "BOOL"
    Boolean = "BOOLEAN"

    Serial    = "SERIAL"
    BigSerial = "BIGSERIAL"

    Json  = "JSON"
    Jsonb = "JSONB"

    Array = "ARRAY"

    SqlTypes = map[string]int{
        Bit:       NUMERIC_TYPE,
        TinyInt:   NUMERIC_TYPE,
        SmallInt:  NUMERIC_TYPE,
        MediumInt: NUMERIC_TYPE,
        Int:       NUMERIC_TYPE,
        Integer:   NUMERIC_TYPE,
        BigInt:    NUMERIC_TYPE,

        Enum:  TEXT_TYPE,
        Set:   TEXT_TYPE,
        Json:  TEXT_TYPE,
        Jsonb: TEXT_TYPE,

        Char:       TEXT_TYPE,
        NChar:      TEXT_TYPE,
        Varchar:    TEXT_TYPE,
        NVarchar:   TEXT_TYPE,
        TinyText:   TEXT_TYPE,
        Text:       TEXT_TYPE,
        NText:      TEXT_TYPE,
        MediumText: TEXT_TYPE,
        LongText:   TEXT_TYPE,
        Uuid:       TEXT_TYPE,
        Clob:       TEXT_TYPE,
        SysName:    TEXT_TYPE,

        Date:          TIME_TYPE,
        DateTime:      TIME_TYPE,
        Time:          TIME_TYPE,
        TimeStamp:     TIME_TYPE,
        TimeStampz:    TIME_TYPE,
        SmallDateTime: TIME_TYPE,
        Year:          TIME_TYPE,

        Decimal:    NUMERIC_TYPE,
        Numeric:    NUMERIC_TYPE,
        Real:       NUMERIC_TYPE,
        Float:      NUMERIC_TYPE,
        Double:     NUMERIC_TYPE,
        Money:      NUMERIC_TYPE,
        SmallMoney: NUMERIC_TYPE,

        Binary:    BLOB_TYPE,
        VarBinary: BLOB_TYPE,

        TinyBlob:         BLOB_TYPE,
        Blob:             BLOB_TYPE,
        MediumBlob:       BLOB_TYPE,
        LongBlob:         BLOB_TYPE,
        Bytea:            BLOB_TYPE,
        UniqueIdentifier: BLOB_TYPE,

        Bool: NUMERIC_TYPE,

        Serial:    NUMERIC_TYPE,
        BigSerial: NUMERIC_TYPE,

        Array: ARRAY_TYPE,
    }
)
var (
    IntType   = reflect.TypeOf(c_INT_DEFAULT)
    Int8Type  = reflect.TypeOf(c_INT8_DEFAULT)
    Int16Type = reflect.TypeOf(c_INT16_DEFAULT)
    Int32Type = reflect.TypeOf(c_INT32_DEFAULT)
    Int64Type = reflect.TypeOf(c_INT64_DEFAULT)

    UintType   = reflect.TypeOf(c_UINT_DEFAULT)
    Uint8Type  = reflect.TypeOf(c_UINT8_DEFAULT)
    Uint16Type = reflect.TypeOf(c_UINT16_DEFAULT)
    Uint32Type = reflect.TypeOf(c_UINT32_DEFAULT)
    Uint64Type = reflect.TypeOf(c_UINT64_DEFAULT)

    Float32Type = reflect.TypeOf(c_FLOAT32_DEFAULT)
    Float64Type = reflect.TypeOf(c_FLOAT64_DEFAULT)

    Complex64Type  = reflect.TypeOf(c_COMPLEX64_DEFAULT)
    Complex128Type = reflect.TypeOf(c_COMPLEX128_DEFAULT)

    StringType = reflect.TypeOf(c_EMPTY_STRING)
    BoolType   = reflect.TypeOf(c_BOOL_DEFAULT)
    ByteType   = reflect.TypeOf(c_BYTE_DEFAULT)
    BytesType  = reflect.SliceOf(ByteType)

    TimeType = reflect.TypeOf(c_TIME_DEFAULT)
)
var (
    PtrIntType   = reflect.PtrTo(IntType)
    PtrInt8Type  = reflect.PtrTo(Int8Type)
    PtrInt16Type = reflect.PtrTo(Int16Type)
    PtrInt32Type = reflect.PtrTo(Int32Type)
    PtrInt64Type = reflect.PtrTo(Int64Type)

    PtrUintType   = reflect.PtrTo(UintType)
    PtrUint8Type  = reflect.PtrTo(Uint8Type)
    PtrUint16Type = reflect.PtrTo(Uint16Type)
    PtrUint32Type = reflect.PtrTo(Uint32Type)
    PtrUint64Type = reflect.PtrTo(Uint64Type)

    PtrFloat32Type = reflect.PtrTo(Float32Type)
    PtrFloat64Type = reflect.PtrTo(Float64Type)

    PtrComplex64Type  = reflect.PtrTo(Complex64Type)
    PtrComplex128Type = reflect.PtrTo(Complex128Type)

    PtrStringType = reflect.PtrTo(StringType)
    PtrBoolType   = reflect.PtrTo(BoolType)
    PtrByteType   = reflect.PtrTo(ByteType)

    PtrTimeType = reflect.PtrTo(TimeType)
)

func SQLType2Type Uses

func SQLType2Type(st SQLType) reflect.Type

default sql type change to go types

type Column Uses

type Column struct {
    Name            string
    TableName       string
    FieldName       string // Avaiable only when parsed from a struct
    SQLType         SQLType
    IsJSON          bool
    Length          int
    Length2         int
    Nullable        bool
    Default         string
    Indexes         map[string]int
    IsPrimaryKey    bool
    IsAutoIncrement bool
    MapType         int
    IsCreated       bool
    IsUpdated       bool
    IsDeleted       bool
    IsCascade       bool
    IsVersion       bool
    DefaultIsEmpty  bool // false means column has no default set, but not default value is empty
    EnumOptions     map[string]int
    SetOptions      map[string]int
    DisableTimeZone bool
    TimeZone        *time.Location // column specified time zone
    Comment         string
}

Column defines database column

func NewColumn Uses

func NewColumn(name, fieldName string, sqlType SQLType, len1, len2 int, nullable bool) *Column

NewColumn creates a new column

func (*Column) ConvertID Uses

func (col *Column) ConvertID(sid string) (interface{}, error)

ConvertID converts id content to suitable type according column type

func (*Column) ValueOf Uses

func (col *Column) ValueOf(bean interface{}) (*reflect.Value, error)

ValueOf returns column's filed of struct's value

func (*Column) ValueOfV Uses

func (col *Column) ValueOfV(dataStruct *reflect.Value) (*reflect.Value, error)

ValueOfV returns column's filed of struct's value accept reflevt value

type DBType Uses

type DBType string
const (
    POSTGRES DBType = "postgres"
    SQLITE   DBType = "sqlite3"
    MYSQL    DBType = "mysql"
    MSSQL    DBType = "mssql"
    ORACLE   DBType = "oracle"
)

type Index Uses

type Index struct {
    IsRegular bool
    Name      string
    Type      int
    Cols      []string
}

Index represents a database index

func NewIndex Uses

func NewIndex(name string, indexType int) *Index

NewIndex new an index object

func (*Index) AddColumn Uses

func (index *Index) AddColumn(cols ...string)

AddColumn add columns which will be composite index

func (*Index) Equal Uses

func (index *Index) Equal(dst *Index) bool

func (*Index) XName Uses

func (index *Index) XName(tableName string) string

type PK Uses

type PK []interface{}

func NewPK Uses

func NewPK(pks ...interface{}) *PK

func (*PK) FromString Uses

func (p *PK) FromString(content string) error

func (*PK) IsZero Uses

func (p *PK) IsZero() bool

func (*PK) ToString Uses

func (p *PK) ToString() (string, error)

type Quoter Uses

type Quoter struct {
    Prefix     byte
    Suffix     byte
    IsReserved func(string) bool
}

Quoter represents a quoter to the SQL table name and column name

func (Quoter) IsEmpty Uses

func (q Quoter) IsEmpty() bool

func (Quoter) Join Uses

func (q Quoter) Join(a []string, sep string) string

func (Quoter) JoinWrite Uses

func (q Quoter) JoinWrite(b *strings.Builder, a []string, sep string) error

func (Quoter) Quote Uses

func (q Quoter) Quote(s string) string

func (Quoter) QuoteTo Uses

func (q Quoter) QuoteTo(buf *strings.Builder, value string) error

QuoteTo quotes the table or column names. i.e. if the quotes are [ and ]

name -> [name]
`name` -> [name]
[name] -> [name]
schema.name -> [schema].[name]
`schema`.`name` -> [schema].[name]
`schema`.name -> [schema].[name]
schema.`name` -> [schema].[name]
[schema].name -> [schema].[name]
schema.[name] -> [schema].[name]
name AS a  ->  [name] AS a
schema.name AS a  ->  [schema].[name] AS a

func (Quoter) Replace Uses

func (q Quoter) Replace(sql string) string

Replace replaces common quote(`) as the quotes on the sql

func (Quoter) Strings Uses

func (q Quoter) Strings(s []string) []string

Strings quotes a slice of string

func (Quoter) Trim Uses

func (q Quoter) Trim(s string) string

Trim removes quotes from s

type SQLType Uses

type SQLType struct {
    Name           string
    DefaultLength  int
    DefaultLength2 int
}

SQLType represents SQL types

func Type2SQLType Uses

func Type2SQLType(t reflect.Type) (st SQLType)

Type2SQLType generate SQLType acorrding Go's type

func (*SQLType) IsArray Uses

func (s *SQLType) IsArray() bool

func (*SQLType) IsBlob Uses

func (s *SQLType) IsBlob() bool

func (*SQLType) IsJson Uses

func (s *SQLType) IsJson() bool

func (*SQLType) IsNumeric Uses

func (s *SQLType) IsNumeric() bool

func (*SQLType) IsText Uses

func (s *SQLType) IsText() bool

func (*SQLType) IsTime Uses

func (s *SQLType) IsTime() bool

func (*SQLType) IsType Uses

func (s *SQLType) IsType(st int) bool

type Table Uses

type Table struct {
    Name string
    Type reflect.Type

    Indexes       map[string]*Index
    PrimaryKeys   []string
    AutoIncrement string
    Created       map[string]bool
    Updated       string
    Deleted       string
    Version       string
    StoreEngine   string
    Charset       string
    Comment       string
    // contains filtered or unexported fields
}

Table represents a database table

func NewEmptyTable Uses

func NewEmptyTable() *Table

NewEmptyTable creates an empty table

func NewTable Uses

func NewTable(name string, t reflect.Type) *Table

NewTable creates a new Table object

func (*Table) AddColumn Uses

func (table *Table) AddColumn(col *Column)

AddColumn adds a column to table

func (*Table) AddIndex Uses

func (table *Table) AddIndex(index *Index)

AddIndex adds an index or an unique to table

func (*Table) AutoIncrColumn Uses

func (table *Table) AutoIncrColumn() *Column

func (*Table) ColumnType Uses

func (table *Table) ColumnType(name string) reflect.Type

func (*Table) Columns Uses

func (table *Table) Columns() []*Column

Columns returns table's columns

func (*Table) ColumnsSeq Uses

func (table *Table) ColumnsSeq() []string

ColumnsSeq returns table's column names according sequence

func (*Table) DeletedColumn Uses

func (table *Table) DeletedColumn() *Column

func (*Table) GetColumn Uses

func (table *Table) GetColumn(name string) *Column

GetColumn returns column according column name, if column not found, return nil

func (*Table) GetColumnIdx Uses

func (table *Table) GetColumnIdx(name string, idx int) *Column

GetColumnIdx returns column according name and idx

func (*Table) IDOfV Uses

func (table *Table) IDOfV(rv reflect.Value) (PK, error)

IDOfV get id from one value of struct

func (*Table) PKColumns Uses

func (table *Table) PKColumns() []*Column

PKColumns reprents all primary key columns

func (*Table) UpdatedColumn Uses

func (table *Table) UpdatedColumn() *Column

func (*Table) VersionColumn Uses

func (table *Table) VersionColumn() *Column

Package schemas imports 10 packages (graph) and is imported by 26 packages. Updated 2020-09-14. Refresh now. Tools for package owners.