mysql

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: May 27, 2024 License: Apache-2.0 Imports: 16 Imported by: 1

README

Mysql

Mysql ORM.

Install

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

Usage

Deploy
app.Deply(mysql.New())
Config

See SQL.

Register driver
import (
    _ "github.com/go-sql-driver/mysql"
)
Register dialect

Add import in deploy src file.

import (
	_ "github.com/aacfactory/fns-contrib/databases/mysql"
)
Define struct

See DAC.

Switch package

Use github.com/aacfactory/fns-contrib/databases/mysql insteadof github.com/aacfactory/fns-contrib/databases/sql/dac.

entry, err = mysql.Insert[Table](ctx, entry) // insteadof dac
Code generator in fn

Add annotation code writer

generates.New(generates.WithAnnotations(mysql.FAG()...))

Use @mysql:transaction annotation. params are readonly and isolation.

  • readonly: set the transaction to be readonly.
  • isolation: use spec isolation. default is use isolation of config.
    • ReadCommitted
    • ReadUncommitted
    • WriteCommitted
    • RepeatableRead
    • Snapshot
    • Serializable
    • Linearizable
// @fn some
// ... some func use transaction
// @mysql:transaction
func some(ctx context.Context, param Param) (result Result, err error) {
	// ...
	return
}

Use @mysql:use annotation to switch datasource service. param is service name and mark it before @mysql:transaction.

// @fn some
// ... some func use transaction
// @mysql:use mysql1
func some(ctx context.Context, param Param) (result Result, err error) {
	// ...
	return
}

Sequence

See Sequence

Note

Virtual column is not fully supported. object and array are same as basic, and select expr of query must be json kind.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ALL added in v1.2.1

func ALL[T Table](ctx context.Context, options ...QueryOption) (entries []T, err error)

func Asc

func Asc(name string) orders.Orders

func Begin added in v1.2.1

func Begin(ctx context.Context, options ...databases.TransactionOption) (err error)

func Between

func Between(field string, left any, right any) conditions.Condition

func Bool added in v1.2.1

func Bool(b bool) conditions.Literal

func Commit added in v1.2.1

func Commit(ctx context.Context) (err error)

func Count

func Count[T Table](ctx context.Context, cond conditions.Condition) (count int64, err error)

func Delete

func Delete[T Table](ctx context.Context, entry T) (v T, ok bool, err error)

func DeleteByCondition added in v1.2.1

func DeleteByCondition[T Table](ctx context.Context, cond conditions.Condition) (affected int64, err error)

func Desc

func Desc(name string) orders.Orders

func Disuse added in v1.2.1

func Disuse(ctx context.Context) context.Context

func Eq

func Eq(field string, expression any) conditions.Condition

func Exist

func Exist[T Table](ctx context.Context, cond conditions.Condition) (has bool, err error)

func FAG added in v1.2.1

func Float added in v1.2.1

func Float(f float32) conditions.Literal

func Float64 added in v1.2.1

func Float64(f float64) conditions.Literal

func Gt added in v1.2.1

func Gt(field string, expression any) conditions.Condition

func Gte added in v1.2.1

func Gte(field string, expression any) conditions.Condition

func In added in v1.2.1

func In(field string, expression ...any) conditions.Condition

func Insert

func Insert[T Table](ctx context.Context, entry T) (v T, ok bool, err error)

func InsertMulti added in v1.2.1

func InsertMulti[T Table](ctx context.Context, entries []T) (affected int64, err error)

func InsertOrUpdate

func InsertOrUpdate[T Table](ctx context.Context, entry T) (v T, ok bool, err error)

func InsertWhenExist

func InsertWhenExist[T Table](ctx context.Context, entry T, source conditions.QueryExpr) (v T, ok bool, err error)

func InsertWhenNotExist

func InsertWhenNotExist[T Table](ctx context.Context, entry T, source conditions.QueryExpr) (v T, ok bool, err error)

func Int added in v1.2.1

func Int(n int) conditions.Literal

func Int64 added in v1.2.1

func Int64(n int64) conditions.Literal

func Like

func Like(field string, expression string) conditions.Condition

func LikeContains added in v1.2.1

func LikeContains(field string, expression string) conditions.Condition

func LikeLast added in v1.2.1

func LikeLast(field string, expression string) conditions.Condition

func Lit added in v1.2.1

func Lit(v string) conditions.Literal

func LitSubQuery added in v1.2.1

func LitSubQuery(query string) conditions.QueryExpr

func Lt added in v1.2.1

func Lt(field string, expression any) conditions.Condition

func Lte added in v1.2.1

func Lte(field string, expression any) conditions.Condition

func Named added in v1.2.1

func Named(name string, value any) sql.NamedArg

func New added in v1.2.1

func New(options ...sql.Option) services.Service

func NotEq

func NotEq(field string, expression any) conditions.Condition

func NotIn

func NotIn(field string, expression ...any) conditions.Condition

func One added in v1.2.1

func One[T Table](ctx context.Context, options ...QueryOption) (entry T, has bool, err error)

func Page

func Page[T Table](ctx context.Context, no int, size int, options ...QueryOption) (page dac.Pager[T], err error)

func Query

func Query[T Table](ctx context.Context, offset int, length int, options ...QueryOption) (entries []T, err error)

func Rollback added in v1.2.1

func Rollback(ctx context.Context)

func String added in v1.2.1

func String(s string) conditions.Literal

func SubQuery added in v1.2.1

func SubQuery(query any, field string, cond conditions.Condition) conditions.QueryExpr

func Time added in v1.2.1

func Time(t time.Time) conditions.Literal

func Tree added in v1.2.1

func Tree[T Table](ctx context.Context, options ...QueryOption) (entry T, err error)

func Trees added in v1.2.1

func Trees[T Table](ctx context.Context, options ...QueryOption) (entries []T, err error)

func Update added in v1.2.1

func Update[T Table](ctx context.Context, entry T) (v T, ok bool, err error)

func UpdateFields added in v1.2.1

func UpdateFields[T Table](ctx context.Context, fields FieldValues, cond conditions.Condition) (affected int64, err error)

func Use added in v1.2.1

func Use(ctx context.Context, endpointName []byte) context.Context

func ViewALL added in v1.2.1

func ViewALL[V View](ctx context.Context, options ...QueryOption) (entries []V, err error)

func ViewOne added in v1.2.1

func ViewOne[V View](ctx context.Context, options ...QueryOption) (entry V, has bool, err error)

func Views added in v1.2.1

func Views[V View](ctx context.Context, offset int, length int, options ...QueryOption) (entries []V, err error)

func WithDatabase added in v1.2.1

func WithDatabase(db databases.Database) sql.Option

func WithName added in v1.2.1

func WithName(name string) sql.Option

func WithTLS added in v1.2.11

func WithTLS(fn RegisterTLSFunc) sql.Option

Types

type FieldValues added in v1.2.1

type FieldValues dac.FieldValues

func Field added in v1.2.1

func Field(name string, value any) FieldValues

func (FieldValues) Field added in v1.2.1

func (fields FieldValues) Field(name string, value any) FieldValues

type QueryOption added in v1.2.1

type QueryOption dac.QueryOption

func Conditions

func Conditions(cond conditions.Condition) QueryOption

func GroupBy added in v1.2.1

func GroupBy(by groups.GroupBy) QueryOption

func Orders

func Orders(order orders.Orders) QueryOption

type QueryOptions added in v1.2.1

type QueryOptions struct {
	dac.QueryOption
}

type RegisterTLSFunc added in v1.2.11

type RegisterTLSFunc func(config *tls.Config) (err error)

type Table

type Table interface {
	dac.Table
}

type View added in v1.2.1

type View interface {
	dac.View
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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