db

package
v0.0.0-...-cca27e0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close() error

Close connection

func Format

func Format(v any) []any

func GetDB

func GetDB(ctx context.Context, uuid string) *gorm.DB

GetDB GetDB

func Load

func Load(config Config) error

Load Load

func Stream

func Stream(ctx context.Context, db *sql.DB, query string, args []any, handle func(index int64, row []any) error) (int64, error)

Types

type Config

type Config struct {
	DriverName string `json:"DriverName" yaml:"DriverName"`
	UUID       string `json:"UUID" yaml:"UUID"`
	DSN        string `json:"DSN" yaml:"DSN"`
	Database   string `json:"Database" yaml:"Database"`
}

Config config

type DB

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

DB my

func Get

func Get(uuid string) *DB

func New

func New(driver, dsn string, opts ...Option) (*DB, error)

New new

func WithDB

func WithDB(db *gorm.DB) *DB

WithDB with db

func (*DB) Close

func (my *DB) Close() error

Close connection

func (*DB) DB

func (my *DB) DB(ctx context.Context) *gorm.DB

DB db

func (*DB) SetMaxOpenConns

func (my *DB) SetMaxOpenConns(max int) error

SetMaxOpenConns SetMaxOpenConns

func (*DB) Stream

func (my *DB) Stream(ctx context.Context, query string, args []any, f func(int64, []any) error) (int64, error)

type M

type M map[string]any

func (M) SubSQL

func (m M) SubSQL() (string, []any, error)

type Model

type Model interface {
	TableName() string
}

Model model

type Option

type Option func(*Options)

Option func

func CreatedAt

func CreatedAt() Option

CreatedAt Set createdAt

func Database

func Database(database string) Option

Database database

func Debug

func Debug(debug bool) Option

Debug debug

func Limit

func Limit(limit int) Option

Limit set limit

func Omit

func Omit(omit ...string) Option

Omit omit

func Table

func Table(table string) Option

Table => mysql: tableName; mongodb;collection

func Tx

func Tx(tx *DB) Option

Tx tx

func UpdatedAt

func UpdatedAt() Option

UpdatedAt set updatedAt

type Options

type Options struct {
	Debug     bool
	Database  string // mysql: database; mongodb;database
	Table     string // mysql: table; mongodb;collection
	CreatedAt time.Time
	UpdatedAt time.Time
	Limit     int
	Omit      []string // 忽略字段; mysql:Omit(columns...)
	Tx        *DB
}

Options options

func NewOptions

func NewOptions(opts ...Option) Options

NewOptions new options

type SearchBody

type SearchBody struct {
	Raw          string   `json:"Raw,omitempty"`
	Namespace    string   `json:"Namespace,omitempty"`
	ResultColumn []string `json:"ResultColumn,omitempty"`
	Condition    []M      `json:"Condition,omitempty"`
	Offset       int      `json:"Offset,omitempty"`
	Limit        int      `json:"Limit,omitempty"`
	Comment      string   `json:"Comment,omitempty"`
}

func (*SearchBody) SQL

func (s *SearchBody) SQL() (string, []any, error)

Jump to

Keyboard shortcuts

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