sql

package module
v0.12.2 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2022 License: Apache-2.0 Imports: 10 Imported by: 10

README

SQL

One sql service for fns.

Features

  • Global transaction
  • Proxy
  • Support master slaver kind
  • Support cluster kind

Install

go get github.com/aacfactory/fns-contrib/databases/sql

Usage

Config
  • Standalone type
    • masterSlaverMode = false
    • dsn size is one
  • Master slaver type
    • masterSlaverMode = true
    • first of dsn is master, afters are slavers
  • Cluster type
    • masterSlaverMode = false
    • all in dsn is members

Example:

sql:
  masterSlaverMode: false,
  driver: "postgres",
  dsn:
    - "username:password@tcp(ip:port)/databases"
  maxIdles: 0
  maxOpens: 0
  enableDebugLog: true
  gtmCleanUpSecond: 120
  isolation: 2
Import driver
import _ "github.com/go-sql-driver/mysql"
Deploy
app.Deply(sql.Service())
Proxy usage

See proxy.go

// begin transaction 
sql.BeginTransaction(ctx)
// commit transaction
sql.CommitTransaction(ctx)
// query
sql.Query(ctx, querySQL, ...)
// execute
sql.Execute(ctx, executeSQL, ...)
ORM usage

Documentation

Index

Constants

View Source
const (
	StringType  = ColumnType("string")
	IntType     = ColumnType("int")
	FloatType   = ColumnType("float")
	BytesType   = ColumnType("bytes")
	JsonType    = ColumnType("json")
	BoolType    = ColumnType("bool")
	TimeType    = ColumnType("time")
	UnknownType = ColumnType("unknown")
)

Variables

This section is empty.

Functions

func BeginTransaction added in v0.8.1

func BeginTransaction(ctx context.Context) (err errors.CodeError)

func CommitTransaction added in v0.8.1

func CommitTransaction(ctx context.Context) (err errors.CodeError)

func Execute

func Execute(ctx context.Context, query string, args ...interface{}) (affected int64, lastInsertId int64, err errors.CodeError)

func RollbackTransaction added in v0.8.1

func RollbackTransaction(ctx context.Context) (err errors.CodeError)

func Service

func Service() service.Service

Types

type Column

type Column interface {
	Type() (typ string)
	Name() (v string)
	IsNil() (ok bool)
	Get(v interface{}) (err error)
	RawValue() (raw []byte)
}

type ColumnScanner added in v0.9.6

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

func NewColumnScanner added in v0.9.6

func NewColumnScanner(ct *sql.ColumnType) (scanner *ColumnScanner)

func (ColumnScanner) Get added in v0.12.1

func (c ColumnScanner) Get(v interface{}) (err error)

func (ColumnScanner) IsNil added in v0.12.1

func (c ColumnScanner) IsNil() (ok bool)

func (ColumnScanner) Name added in v0.12.1

func (c ColumnScanner) Name() (v string)

func (ColumnScanner) RawValue added in v0.12.1

func (c ColumnScanner) RawValue() (raw []byte)

func (*ColumnScanner) Scan added in v0.9.6

func (c *ColumnScanner) Scan(src interface{}) error

func (ColumnScanner) Type added in v0.12.1

func (c ColumnScanner) Type() (typ string)

type ColumnType

type ColumnType string

type FieldColumn added in v0.3.10

type FieldColumn struct {
	Kind      string
	FieldType reflect.Type
	Column    *Column
}

type NullJson

type NullJson struct {
	Json  json.RawMessage
	Valid bool
}

func (*NullJson) Scan

func (v *NullJson) Scan(src interface{}) error

type NullSQLRaw

type NullSQLRaw struct {
	Raw   sql.RawBytes
	Valid bool
}

func (*NullSQLRaw) Scan

func (v *NullSQLRaw) Scan(src interface{}) error

type Row

type Row interface {
	json.Marshaler
	json.Unmarshaler
	Empty() (ok bool)
	Columns() (columns []Column)
	Column(name string, value interface{}) (has bool, err error)
}

type Rows

type Rows interface {
	json.Marshaler
	json.Unmarshaler
	Empty() (ok bool)
	Size() int
	Next() (v Row, has bool)
}

func Query

func Query(ctx context.Context, query string, args ...interface{}) (v Rows, err errors.CodeError)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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