sqlmapper

package
v0.0.0-...-193f563 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2018 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SQLRowsToRows

func SQLRowsToRows(rows *sql.Rows) ([]interface{}, error)

SQLRowsToRows return rows from sql.Rows

Types

type ColData

type ColData struct {
	Name     string      `json:"name"`
	Data     interface{} `json:"data"`
	DataType string      `json:"data_type"`
}

ColData hold data of a column

type Ctx

type Ctx map[string]interface{}

Ctx for current sqlmapper data context

func (Ctx) ToRowData

func (c Ctx) ToRowData() RowData

ToRowData convert Ctx back to RowData

type Filter

type Filter struct {
	Operator   string      `json:"operator"` // "="
	ColumnName string      `json:"column_name"`
	Value      interface{} `json:"value"`
}

Filter containt filter

func (*Filter) IsZero

func (f *Filter) IsZero() bool

IsZero check filter is empty

type Mapper

type Mapper interface {
	Create(dbName, tableName string, d RowData) (RowData, error)
	Update(dbName, tableName string, d RowData) (RowData, error)
	Delete(dbName, tableName string, fields, data []interface{}) error
	Query(Query) ([]string, []interface{}, error)
	RawQuery(dbName string, sql string) ([]string, []database.Column, []interface{}, error)
	ColumnMetadata(Query) ([]database.Column, error)
	ColumnMetadataByRows(*sql.Rows) ([]database.Column, error)
	Explain(dbName string, sql string) (interface{}, error)
}

Mapper interface for mapping query from sql to corresponding database engine

type Query

type Query struct {
	SourceDatabase string   `json:"-"`
	SourceTable    string   `json:"-"`
	Fields         []string `json:"fields"`
	Filter         Filter   `json:"filter"`
	Offset         int      `json:"offset"`
	Limit          int      `json:"limit"`
	Order          []string `json:"order"` // 2 elements: "columnName" and "asc" if ascending order, "desc" if descending order
}

Query contain query data for a query request

func (*Query) ColumnMetadata

func (q *Query) ColumnMetadata(columns []database.Column) ([]database.Column, error)

ColumnMetadata convert query to column spec

func (*Query) ColumnNames

func (q *Query) ColumnNames() string

ColumnNames return columns name in query

func (*Query) Columns

func (q *Query) Columns() []string

Columns return columsn from query

func (*Query) OrderSequence

func (q *Query) OrderSequence() string

OrderSequence return order sequence of columns in query

type QueryPlan

type QueryPlan struct {
	NodeType      string `json:"Node Type"`
	ParallelAware bool   `json:"Parallel Aware"`
	RelationName  string `json:"Relation Name"`
	Alias         string `json:"Alias"`
}

QueryPlan .

type QueryResult

type QueryResult RowData

QueryResult hold data of a query have result is 1 row

func RowToQueryResult

func RowToQueryResult(row *sql.Row, colDefines []database.Column) (QueryResult, error)

RowToQueryResult rows to query result

func (QueryResult) MarshalJSON

func (r QueryResult) MarshalJSON() ([]byte, error)

MarshalJSON encode json of a row

type QueryResults

type QueryResults []RowData

QueryResults hold data of a query more than 1 row

type RowData

type RowData map[string]ColData

RowData hold data of a row

func MakeRowData

func MakeRowData(fields []interface{}, data []interface{}) (RowData, error)

MakeRowData make row_data from fields([]string) and data([]{}interface)

func (RowData) Columns

func (r RowData) Columns() []string

Columns return columns listed in RowData

func (RowData) ColumnsAndData

func (r RowData) ColumnsAndData() ([]string, []interface{})

ColumnsAndData return columns and data of a row_data

func (RowData) MarshalJSON

func (r RowData) MarshalJSON() ([]byte, error)

MarshalJSON encode json of a row

func (RowData) RelateData

func (r RowData) RelateData() map[string][]RowData

RelateData get all relate-data

func (RowData) ToCtx

func (r RowData) ToCtx() Ctx

ToCtx return map[string]interface{} from a RowData

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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