bear

package module
v0.0.84 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2021 License: MIT Imports: 12 Imported by: 0

README

Bear

A go language sql builder.

Why Bear

Lightweight, lower dependence and efficient.

Quick Start

package main

import (
	"fmt"
	"github.com/medivhyang/bear"

	_ "github.com/medivhyang/bear/dialect/sqlite3"
)

func main() {
	s := bear.NewBuilder().Select("user", "id", "name", "age").Build()
	fmt.Println(s)
}

More examples refer to /examples

Documentation

Index

Constants

View Source
const (
	TagKey          = "bear"
	TagChildKeyName = "name"
	TagItemSep      = ","
	TagKVSep        = "="
)

Variables

View Source
var (
	ErrNotFoundDialect        = errorf("dialect", "not found")
	ErrInvalidDialectInstance = errorf("dialect", "invalid instance")
)

Functions

func Debug added in v0.0.82

func Debug(b bool)

func Output added in v0.0.83

func Output(writer io.Writer)

func RegisterDefaultDialect added in v0.0.60

func RegisterDefaultDialect(name string, dialect Dialect)

func RegisterDialect

func RegisterDialect(name string, dialect Dialect)

func SetDefaultDialect

func SetDefaultDialect(name string) bool

Types

type Action added in v0.0.83

type Action string

type Builder added in v0.0.83

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

func NewBuilder added in v0.0.83

func NewBuilder(options ...BuilderOptionFunc) *Builder

func (*Builder) Apply added in v0.0.83

func (b *Builder) Apply(options ...BuilderOptionFunc) *Builder

func (*Builder) Build added in v0.0.83

func (b *Builder) Build() Template

func (*Builder) Delete added in v0.0.83

func (b *Builder) Delete(table string) *Builder

func (*Builder) Dialect added in v0.0.83

func (b *Builder) Dialect(d string) *Builder

func (*Builder) GroupBy added in v0.0.83

func (b *Builder) GroupBy(fields ...string) *Builder

func (*Builder) Having added in v0.0.83

func (b *Builder) Having(format string, values ...interface{}) *Builder

func (*Builder) Insert added in v0.0.83

func (b *Builder) Insert(table string, columns map[string]interface{}) *Builder

func (*Builder) InsertStruct added in v0.0.83

func (b *Builder) InsertStruct(table string, i interface{}, ignoreZeroValue bool, ignoreFields ...string) *Builder

func (*Builder) OrderBy added in v0.0.83

func (b *Builder) OrderBy(fields ...string) *Builder

func (*Builder) Paging added in v0.0.83

func (b *Builder) Paging(page, size int) *Builder

func (*Builder) Select added in v0.0.83

func (b *Builder) Select(table string, columns ...string) *Builder

func (*Builder) SelectStruct added in v0.0.83

func (b *Builder) SelectStruct(table string, i interface{}, ignoreFields ...string) *Builder

func (*Builder) Update added in v0.0.83

func (b *Builder) Update(table string, columns map[string]interface{}) *Builder

func (*Builder) UpdateStruct added in v0.0.83

func (b *Builder) UpdateStruct(table string, i interface{}, ignoreZeroValue bool, ignoreFields ...string) *Builder

func (*Builder) Where added in v0.0.83

func (b *Builder) Where(format string, values ...interface{}) *Builder

func (*Builder) WhereIn added in v0.0.83

func (b *Builder) WhereIn(column string, values ...interface{}) *Builder

type BuilderOptionFunc added in v0.0.83

type BuilderOptionFunc func(b *Builder)

func Delete

func Delete(table string) BuilderOptionFunc

func GroupBy added in v0.0.83

func GroupBy(fields ...string) BuilderOptionFunc

func Having added in v0.0.83

func Having(format string, values ...interface{}) BuilderOptionFunc

func Insert

func Insert(table string, columns map[string]interface{}) BuilderOptionFunc

func OrderBy added in v0.0.83

func OrderBy(fields ...string) BuilderOptionFunc

func Paging added in v0.0.83

func Paging(page, size int) BuilderOptionFunc

func Select

func Select(table string, columns ...string) BuilderOptionFunc

func SelectStruct added in v0.0.18

func SelectStruct(table string, i interface{}, ignoreColumns ...string) BuilderOptionFunc

func Update

func Update(table string, columns map[string]interface{}) BuilderOptionFunc

func Where added in v0.0.83

func Where(format string, values ...interface{}) BuilderOptionFunc

func WhereIn added in v0.0.83

func WhereIn(column string, values ...interface{}) BuilderOptionFunc

func WithDialect added in v0.0.58

func WithDialect(d string) BuilderOptionFunc

type BulkBuilder added in v0.0.83

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

func NewBulkBuilder added in v0.0.83

func NewBulkBuilder() *BulkBuilder

func (*BulkBuilder) Append added in v0.0.83

func (b *BulkBuilder) Append(row Templates) *BulkBuilder

func (*BulkBuilder) AppendMap added in v0.0.83

func (b *BulkBuilder) AppendMap(row map[string]interface{}) *BulkBuilder

func (*BulkBuilder) AppendStruct added in v0.0.83

func (b *BulkBuilder) AppendStruct(i interface{}, ignoreFields ...string) *BulkBuilder

func (*BulkBuilder) Build added in v0.0.83

func (b *BulkBuilder) Build() Template

func (*BulkBuilder) Dialect added in v0.0.83

func (b *BulkBuilder) Dialect(name string) *BulkBuilder

func (*BulkBuilder) Table added in v0.0.83

func (b *BulkBuilder) Table(name string) *BulkBuilder

type Conditions added in v0.0.60

type Conditions []Template

func NewConditions added in v0.0.60

func NewConditions(tt ...Template) Conditions

func (Conditions) And added in v0.0.83

func (cc Conditions) And() Template

func (Conditions) Append added in v0.0.60

func (cc Conditions) Append(others ...Template) Conditions

func (Conditions) AppendMap added in v0.0.83

func (cc Conditions) AppendMap(m map[string]interface{}) Conditions

func (Conditions) AppendStruct added in v0.0.83

func (cc Conditions) AppendStruct(i interface{}, ignoreZeroValue bool) Conditions

func (Conditions) Appendf added in v0.0.83

func (cc Conditions) Appendf(format string, values ...interface{}) Conditions

func (Conditions) Join added in v0.0.83

func (cc Conditions) Join(sep string, right, left string) Template

func (Conditions) Or added in v0.0.83

func (cc Conditions) Or() Template

type DB added in v0.0.37

type DB struct {
	Raw *sql.DB
}

func NewDB added in v0.0.83

func NewDB(db *sql.DB) *DB

func OpenDB added in v0.0.83

func OpenDB(driverName string, dataSourceName string) (*DB, error)

func (*DB) Exec added in v0.0.42

func (db *DB) Exec(ctx context.Context, t Template) (sql.Result, error)

func (*DB) Query added in v0.0.42

func (db *DB) Query(ctx context.Context, t Template, i interface{}) error

type DDLBuilder added in v0.0.83

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

func NewDDLBuilder added in v0.0.83

func NewDDLBuilder(dialect ...string) *DDLBuilder

func (*DDLBuilder) Build added in v0.0.83

func (b *DDLBuilder) Build() Template

func (*DDLBuilder) Compact added in v0.0.83

func (b *DDLBuilder) Compact() *DDLBuilder

func (*DDLBuilder) CreateTable added in v0.0.83

func (b *DDLBuilder) CreateTable(table DDLTable, checkExists bool) *DDLBuilder

func (*DDLBuilder) Dialect added in v0.0.83

func (b *DDLBuilder) Dialect(name string) *DDLBuilder

func (*DDLBuilder) DropTable added in v0.0.83

func (b *DDLBuilder) DropTable(table string, checkExists bool) *DDLBuilder

func (*DDLBuilder) Pretty added in v0.0.83

func (b *DDLBuilder) Pretty(prefix string, indent string) *DDLBuilder

type DDLColumn added in v0.0.83

type DDLColumn struct {
	Name   string
	Type   string
	Suffix string
}

type DDLTable added in v0.0.83

type DDLTable struct {
	Name    string
	Columns []DDLColumn
}

type Dialect

type Dialect interface {
	Mapping(rt reflect.Type) string
	Quote(s string) string
}

func GetDialect added in v0.0.83

func GetDialect(name string) Dialect

func LookupDialect added in v0.0.60

func LookupDialect(name string) Dialect

type Rows

type Rows struct {
	Raw *sql.Rows
}

func NewRows added in v0.0.83

func NewRows(rows *sql.Rows) *Rows

func (*Rows) Bind added in v0.0.83

func (r *Rows) Bind(i interface{}) error

func (*Rows) Map

func (r *Rows) Map() (map[string]interface{}, error)

func (*Rows) MapSlice

func (r *Rows) MapSlice() ([]map[string]interface{}, error)

func (*Rows) Scalar added in v0.0.32

func (r *Rows) Scalar(value interface{}) error

func (*Rows) ScalarSlice added in v0.0.32

func (r *Rows) ScalarSlice(slice interface{}) error

func (*Rows) Scan

func (r *Rows) Scan(callback func(scan func(...interface{}) error, abort func()) error) error

func (*Rows) Struct

func (r *Rows) Struct(i interface{}) error

func (*Rows) StructSlice

func (r *Rows) StructSlice(i interface{}) error

type Template

type Template struct {
	Format string
	Values []interface{}
}

func NewTemplate added in v0.0.18

func NewTemplate(format string, values ...interface{}) Template

func (Template) Append

func (t Template) Append(others ...Template) Template

func (Template) AppendValues added in v0.0.83

func (t Template) AppendValues(values ...interface{}) Template

func (Template) Appendf added in v0.0.83

func (t Template) Appendf(format string, values ...interface{}) Template

func (Template) Bracket added in v0.0.83

func (t Template) Bracket() Template

func (Template) String added in v0.0.3

func (t Template) String() string

func (Template) Wrap

func (t Template) Wrap(left string, right string) Template

type Templates added in v0.0.83

type Templates []Template

func NewTemplates added in v0.0.83

func NewTemplates(tt ...Template) Templates

func PlainTemplates added in v0.0.83

func PlainTemplates(ss ...string) Templates

func (Templates) Append added in v0.0.83

func (tt Templates) Append(others ...Template) Templates

func (Templates) Appendf added in v0.0.83

func (tt Templates) Appendf(format string, values ...interface{}) Templates

func (Templates) Formats added in v0.0.83

func (tt Templates) Formats() []string

func (Templates) Join added in v0.0.83

func (tt Templates) Join(sep string, right, left string) Template

func (Templates) Values added in v0.0.83

func (tt Templates) Values() []interface{}

Directories

Path Synopsis
dialect
examples
hello command

Jump to

Keyboard shortcuts

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