torm

package module
v0.0.0-...-f986c1d Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2019 License: Apache-2.0 Imports: 11 Imported by: 0

README

ThinkORM

ThinkORM is a simple and Powerful ORM for Go.

Build Status Go Report Card Go Report Card GoDoc Join the chat Latest Stable Version License

Installation

go get github.com/thinkoner/torm

Quick start

Get the database connection:
config := torm.Config{
		Driver: "mysql",
		Dsn:    "root:abc-123@tcp(127.0.0.1:3306)/test?charset=utf8&parseTime=true",
	}
db, _ := torm.Open(config)
Query Builder:
type User struct {
	Name      string `torm:"column:name"`
	Gender    string `torm:"column:gender"`
	Addr      string
	BirthDate string
	Balance   float64
	CreatedAt time.Time
	UpdatedAt time.Time
}

func (u *User) TableName() string {
	return "users"
}

var users []User
db.Table("users").
	Where("gender", "M").
	Where("name", "like", "%a%").
	WhereColumn("created_at", "!=", "updated_at").
	WhereIn("addr", []interface{}{"Columbia", "Alaska"}).
	WhereBetween("birth_date", []interface{}{"1990-01-01", "1999-12-31"}).
	Get(&users)

License

This project is licensed under the Apache 2.0 license.

Contact

If you have any issues or feature requests, please contact us. PR is welcomed.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Binding

type Binding []interface{}

type Builder

type Builder struct {
	Connection *Connection

	Query    *query.Query
	Bindings map[string][]interface{}
	// contains filtered or unexported fields
}

func NewBuilder

func NewBuilder(connection *Connection, grammar grammar.Grammar) *Builder

func (*Builder) AddBinding

func (b *Builder) AddBinding(value interface{}, segment string)

AddBinding Add a binding to the query.

func (*Builder) AddSelect

func (b *Builder) AddSelect(columns ...string) *Builder

func (*Builder) Aggregate

func (b *Builder) Aggregate(function string, columns []string, dest ...interface{}) error

Aggregate Execute an aggregate function on the database.

func (*Builder) Avg

func (b *Builder) Avg(columns string, dest ...interface{}) error

Avg Retrieve the average of the values of a given column.

func (*Builder) CloneWithout

func (b *Builder) CloneWithout(properties ...string) *Builder

CloneWithout Clone the query without the given properties.

func (*Builder) CloneWithoutBindings

func (b *Builder) CloneWithoutBindings(except ...string) *Builder

CloneWithoutBindings Clone the query without the given bindings.

func (*Builder) Count

func (b *Builder) Count(dest ...interface{}) error

Count Retrieve the "count" result of the query.

func (*Builder) Delete

func (b *Builder) Delete(args ...interface{}) (int64, error)

Delete a record from the database.

func (*Builder) First

func (b *Builder) First(dest interface{}, columns ...interface{}) error

func (*Builder) From

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

From Set the table which the query is targeting.

func (*Builder) Get

func (b *Builder) Get(dest interface{}, columns ...interface{}) error

func (*Builder) GetBindings

func (b *Builder) GetBindings() []interface{}

func (*Builder) GetConnection

func (b *Builder) GetConnection() *Connection

GetConnection Get the database connection instance.

func (*Builder) GetGrammar

func (b *Builder) GetGrammar() grammar.Grammar

GetGrammar Get the query grammar instance.

func (*Builder) GroupBy

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

GroupBy Add a "group by" clause to the query.

func (*Builder) Having

func (b *Builder) Having(column string, args ...interface{}) *Builder

Having Add a "having" clause to the query.

func (*Builder) Insert

func (b *Builder) Insert(value map[string]interface{}) (int64, int64, error)

Insert Insert a new record into the database.

func (*Builder) Inserts

func (b *Builder) Inserts(values []map[string]interface{}) (int64, int64, error)

Inserts Bulk insert records into the database.

func (*Builder) Join

func (b *Builder) Join(table string, first string, args ...interface{}) *Builder

Join Add a join clause to the query.

func (*Builder) Limit

func (b *Builder) Limit(value uint64) *Builder

Limit Set the "limit" value of the query.

func (*Builder) Max

func (b *Builder) Max(columns string, dest ...interface{}) error

Max Retrieve the maximum value of a given column.

func (*Builder) Min

func (b *Builder) Min(columns string, dest ...interface{}) error

Min Retrieve the minimum value of a given column.

func (*Builder) Offset

func (b *Builder) Offset(value uint64) *Builder

Offset Set the "offset" value of the query.

func (*Builder) OrWhere

func (b *Builder) OrWhere(column string, args ...interface{}) *Builder

OrWhere Add an "or where" clause to the query.

func (*Builder) OrWhereBetween

func (b *Builder) OrWhereBetween(column string, values []interface{}) *Builder

OrWhereBetween Add an or where between statement to the query.

func (*Builder) OrWhereColumn

func (b *Builder) OrWhereColumn(first string, args ...interface{}) *Builder

OrWhereColumn Add an "or where" clause comparing two columns to the query.

func (*Builder) OrWhereIn

func (b *Builder) OrWhereIn(column string, values []interface{}) *Builder

OrWhereIn Add an "or where in" clause to the query.

func (*Builder) OrWhereNotBetween

func (b *Builder) OrWhereNotBetween(column string, values []interface{}) *Builder

OrWhereNotBetween Add an or where not between statement to the query.

func (*Builder) OrWhereNotIn

func (b *Builder) OrWhereNotIn(column string, values []interface{}) *Builder

OrWhereNotIn Add an "or where not in" clause to the query.

func (*Builder) OrWhereNotNull

func (b *Builder) OrWhereNotNull(column string) *Builder

OrWhereNotNull Add an "or where not null" clause to the query.

func (*Builder) OrWhereNull

func (b *Builder) OrWhereNull(column string) *Builder

OrWhereNull Add an "or where null" clause to the query.

func (*Builder) OrWhereRaw

func (b *Builder) OrWhereRaw(sql string, bindings ...interface{}) *Builder

OrWhereRaw Add a raw or where clause to the query.

func (*Builder) OrderBy

func (b *Builder) OrderBy(column string, args ...string) *Builder

OrderBy Add an "order by" clause to the query.

func (*Builder) OrderByDesc

func (b *Builder) OrderByDesc(column string) *Builder

OrderByDesc Add a descending "order by" clause to the query.

func (*Builder) OrderByRaw

func (b *Builder) OrderByRaw(sql string, bindings ...interface{}) *Builder

OrderByRaw Add a raw "order by" clause to the query.

func (*Builder) Scan

func (b *Builder) Scan(dest ...interface{}) error

func (*Builder) Select

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

Select the columns to be selected.

func (*Builder) SelectRaw

func (b *Builder) SelectRaw(expression string, bindings ...interface{}) *Builder

SelectRaw Add a new "raw" select expression to the query.

func (*Builder) Skip

func (b *Builder) Skip(value uint64) *Builder

Skip Alias to set the "offset" value of the query.

func (*Builder) Sum

func (b *Builder) Sum(columns string, dest ...interface{}) error

Sum Retrieve the sum of the values of a given column.

func (*Builder) Take

func (b *Builder) Take(value uint64) *Builder

Take Alias to set the "limit" value of the query.

func (*Builder) ToSql

func (b *Builder) ToSql() string

func (*Builder) Update

func (b *Builder) Update(value map[string]interface{}) (int64, error)

Update a record in the database.

func (*Builder) Where

func (b *Builder) Where(column string, args ...interface{}) *Builder

Where Add a basic where clause to the query.

func (*Builder) WhereBetween

func (b *Builder) WhereBetween(column string, values []interface{}, args ...interface{}) *Builder

WhereBetween Add a where between statement to the query.

func (*Builder) WhereColumn

func (b *Builder) WhereColumn(first string, args ...interface{}) *Builder

WhereColumn Add a "where" clause comparing two columns to the query.

func (*Builder) WhereIn

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

WhereIn Add a "where in" clause to the query.

func (*Builder) WhereNotBetween

func (b *Builder) WhereNotBetween(column string, values []interface{}, args ...interface{}) *Builder

WhereNotBetween Add a where not between statement to the query.

func (*Builder) WhereNotIn

func (b *Builder) WhereNotIn(column string, values []interface{}, args ...interface{}) *Builder

WhereNotIn Add a "where not in" clause to the query.

func (*Builder) WhereNotNull

func (b *Builder) WhereNotNull(column string, args ...interface{}) *Builder

WhereNotNull Add a "where not null" clause to the query.

func (*Builder) WhereNull

func (b *Builder) WhereNull(column string, args ...interface{}) *Builder

WhereNull Add a "where null" clause to the query.

func (*Builder) WhereRaw

func (b *Builder) WhereRaw(sql string, bindings ...interface{}) *Builder

WhereRaw Add a raw where clause to the query.

type Config

type Config struct {
	Driver string
	Prefix string
	Dsn    string
}

type Connection

type Connection struct {
	DB *sql.DB
	// contains filtered or unexported fields
}

func Open

func Open(config Config) (*Connection, error)

func (*Connection) Create

func (c *Connection) Create(model interface{}) error

Create Save a new model to the database.

func (*Connection) Delete

func (c *Connection) Delete(query string, args ...interface{}) (int64, error)

Delete Run a delete statement against the database.

func (*Connection) Destroy

func (c *Connection) Destroy(model interface{}) error

Destroy Destroy the model.

func (*Connection) GetQueryGrammar

func (c *Connection) GetQueryGrammar() grammar.Grammar

func (*Connection) Insert

func (c *Connection) Insert(query string, args ...interface{}) (int64, int64, error)

Insert Run an insert statement against the database.

func (*Connection) Model

func (c *Connection) Model(model interface{}) *Builder

Model Begin a fluent query against a database Model.

func (*Connection) Query

func (c *Connection) Query() *Builder

Query Get a new query builder instance.

func (*Connection) Save

func (c *Connection) Save(model interface{}) error

Save Save the model to the database.

func (*Connection) Scan

func (c *Connection) Scan(query string, bindings []interface{}, dest ...interface{}) error

func (*Connection) Select

func (c *Connection) Select(query string, bindings []interface{}, dest interface{}) error

Select Run a select statement against the database.

func (*Connection) SelectOne

func (c *Connection) SelectOne(query string, bindings []interface{}, dest interface{}) error

SelectOne Run a select statement and return a single result.

func (*Connection) Statement

func (c *Connection) Statement(query string, args ...interface{}) error

Statement Execute an SQL statement and return the boolean result.

func (*Connection) Table

func (c *Connection) Table(table string) *Builder

Table Begin a fluent query against a database table.

func (*Connection) Update

func (c *Connection) Update(query string, args ...interface{}) (int64, error)

Update Run an update statement against the database.

type Field

type Field struct {
	Value       reflect.Value
	StructField reflect.StructField
	Attrs       map[string]string
	Primary     bool
	Name        string
	Ignored     bool
	IsBlank     bool
}

Field The model field definition

func NewField

func NewField(value reflect.Value, structField reflect.StructField) *Field

func (*Field) GetAttr

func (f *Field) GetAttr(key string) (string, bool)

GetParams Get the attr of tag

func (*Field) SetValue

func (f *Field) SetValue(value interface{}) (err error)

Set set a value to the field

type JoinClause

type JoinClause struct {
	Builder
	Type          string
	Table         string
	ParentBuilder *Builder
}

func NewJoinClause

func NewJoinClause(parentBuilder *Builder, typeStr string, table string) *JoinClause

type Manager

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

Database manager.

func (*Manager) Connect

func (m *Manager) Connect(name string) (*Connection, error)

Connect Get a database connection instance.

type Model

type Schema

type Schema struct {
	Fields       []*Field
	PrimaryField *Field
	// contains filtered or unexported fields
}

Schema model definition

func NewSchema

func NewSchema(model interface{}) (*Schema, error)

func (*Schema) Attributes

func (s *Schema) Attributes() map[string]interface{}

func (*Schema) SetId

func (s *Schema) SetId(id int64) error

type SoftDeletes

type SoftDeletes struct {
	field.DeletedAtAttr
}

type TableName

type TableName interface {
	TableName() string
}

Directories

Path Synopsis
driver

Jump to

Keyboard shortcuts

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