opal

package module
v0.0.0-...-7175c3e Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2016 License: MIT Imports: 16 Imported by: 0

README

This was a tech spike. Do not use this code. This is being re coded from scratch at myesui/opal

opal

A Go ORM which implements the ActiveRecord pattern

In development API in no way guaranteed.

Currently only supports Sqlite3

#Use

Each domain must first create and initialise its models.

To achieve this you must implement the BaseModel interface and pass it into Gemma's StartArgs.

package domain

var (
	domains = [...]Domain{
	new(Person),
	new(Pet),
	new(Order),
	new(Country),
}
)

type YourBaseModel struct {}

func (YourBaseModel) Models() []Domain {
	return domains[:]
}

Before you can start using your domain structs you must first generate your domain access code. To do this create a separate go project with the same relative path to your domain objects and simply run the INIT function. Looking to make this step redundant. It is best to keep this separate so the files it generates can be used in your project.

package main

import (
	. "github.com/twinj/opal"
	"myesui/domain"
)

func main() {
INIT(new(domain.YourBaseModel))
}

You are now ready to start using Opal.

import (
	"database/sql"
	"your/domain"
	_ "github.com/mattn/sqlite3"
	. "github.com/twinj/opal"
)

var (
	Em *Gem
)

func wherever() {
 db, err := sql.Open("sqlite3", "file:./person_test.db?cache=shared&mode=rwc")

	args := StartArgs{
		BaseModel: new(domain.YourBaseModel),
		DB: db,
		Dialect: &dialect.Sqlite3{},
	}
	Em = GEM(args)
}

#Features thus far

Models:

type Person struct {
	Entity
	Id       AutoIncrement
	Name     String
}

type Country struct {
	Entity
	Code String
	Description String
}

Model CRUD:

person := domain.InitPerson()
person.Id.A(190)
person.Name.A("Tom Baker")
domain.People.Insert(person)

person.Name.A("Tom Fred Baker")
domain.People.Update(person)

domain.People.Delete(person)

person = domain.People.Find(170)

Model ActiveRecord:

person := domain.NewPerson{
		Id: 400,
		Name: "Frank Cheese",
	}.Save()

person.Name.A("Frank Cheesy").Save()

person.Delete()

Model transactions:

result, ok := GEM.Begin((func(t Transaction) Result {
		person := domain.InitPerson()
		person.Id.A(190)
		person.Name.A("Tom Baker")
		t.Insert(person3)
		person = domain.InitPerson()
		person.Id.A(191)
		person.Name.A("Peter Parker")
		return person.Insert()
	})).Go()

#Other Features

  • Convention over configuration
  • Uses Go Inflect library to name tables

#Planned Features

  • Dialects to support different Sql databases
  • Validation interfaces
  • Relational mapping with maps and interfaces
  • Compound and embedded keys and embedded struct

Documentation

Overview

*

  • Date: 12/03/14
  • Time: 06:34 PM

*

  • Date: 22/02/14
  • Time: 11:17 AM

*

  • Date: 9/02/14
  • Time: 7:06 PM

*

  • Date: 9/02/14
  • Time: 7:03 PM

*

  • Date: 9/02/14
  • Time: 6:40 PM

*

  • Date: 8/02/14
  • Time: 11:22 AM

*

  • Date: 11/02/14
  • Time: 7:17 PM

Index

Constants

View Source
const (
	PrimaryKey reflect.Kind = iota + reflect.UnsafePointer + 1
	OpalTime
	Embedded
	DAO
)

Variables

This section is empty.

Functions

func ABool

func ABool(p bool) *bool

func BindArgs

func BindArgs(pModel Model) []interface{}

Gets all the bind args for a model. Does not include any join columns.

func INIT

func INIT(pBaseModel BaseModel)

INIT will scan each supplied Model/Domain object and generate the relevant Boilerplate code with which you can run TODO doco

func SetMagic

func SetMagic(pId *OpalMagic)

Allows a user to set their own id Can only be run once Initial Gem startup will run this to check

func SwitchGem

func SwitchGem(pGem Gem) bool

Copy a Gem into the packages address to be used as the current service

Types

type Action

type Action func(pTx Transaction) Result

User simplified function types to build transactions

type ActiveRecord

type ActiveRecord interface {

	// Takes a Model saves it as a new data-store entity and
	// returns a result
	Insert(pModel Model) Result

	// Takes a Model, updates an existing entity from the
	// data-store and returns a result
	Save(pModel Model) Result

	// Takes a Model and removes an existing entity from the
	// data-store
	Delete(pModel Model) Result
}

ActiveRecordDAO acts as a data provider for a Model's Entity. It is a limited version of the full Domain access object.

type ActiveRecordDAO

type ActiveRecordDAO interface {

	// Takes a Model saves it as a new data-store entity and
	// returns a result
	Insert(pModel Model) Result

	// Takes a Model, updates an existing entity from the
	// data-store and returns a result
	Save(pModel Model) Result

	// Takes a Model and removes an existing entity from the
	// data-store
	Delete(pModel Model) Result
}

ActiveRecordDAO acts as a data provider for a Model's Entity. It is a limited version of the full Domain access object.

type Args

type Args interface {
	// Retrieve args from the type
	Get() []interface{}
}

Args interface allows you to retrieve the args from any type which implements this

type AutoIncrement

type AutoIncrement struct {
	Int64
}

Is an Int64 under the covers where its name flags its use

func NewAutoIncrement

func NewAutoIncrement(p int64) *AutoIncrement

Makes a new AutoIncrement

type BaseModel

type BaseModel interface {
	Models() []Domain
}

The Base model acts as the container to retrieve all Models and their corresponding metadata in the Domain.

Each domain must define a BaseModel

BaseModel / Entity overlap in function TODO re-consider use and requirement

type Bool

type Bool struct {
	Bool *bool
}

Bool represents an int64 that may be null. Bool implements the Scanner interface so It can be used as a scan destination, similar to sql.NullString.

func NewBool

func NewBool(p bool) Bool

Convenience constructor for an Bool

func (*Bool) A

func (o *Bool) A(p bool)

Convenience setting method

func (Bool) Kind

func (o Bool) Kind() reflect.Kind

Returns the primitive type

func (*Bool) Scan

func (o *Bool) Scan(pValue interface{}) error

Bool implements the sql.Scanner interface.

func (Bool) String

func (o Bool) String() string

Prints the value

func (Bool) Value

func (o Bool) Value() (driver.Value, error)

Bool implements the driver Valuer interface.

type Column

type Column struct {
	Identifier    string
	Name          string
	AutoIncrement bool
	Unique        bool
	Nilable       bool
	Insertable    bool
	Updatable     bool
	Length        uint
	Precision     uint
	Scale         uint
	Kind          reflect.Kind
}

TODO

func (Column) BuildColumnSchema

func (o Column) BuildColumnSchema(pBuilder *SqlBuilder) *SqlBuilder

TODO

func (Column) BuildKeySchema

func (o Column) BuildKeySchema(pBuilder *SqlBuilder) *SqlBuilder

TODO

func (Column) ToSqlType

func (o Column) ToSqlType() string

TODO

type DefaultDialect

type DefaultDialect struct {
}

Sqlite3 implements the Dialect interface

type Dialect

type Dialect interface {

	// All identifiers will be transformed into a string
	// compatible with the dialect to ensure that any keywords
	// that might be used as identifiers do not cause Sql errors.
	// E.g. In Sqlite if you want to use a keyword as a name,
	// you need to quote it:
	//
	// 'keyword'	A keyword in single quotes is a string
	// 		literal.
	//
	// "keyword"	A keyword in double-quotes is an identifier.
	//
	// [keyword]	A keyword enclosed in square brackets is an
	//		identifier. This is not standard SQL. This quoting
	// 		mechanism is used by MS Access and  SQL Server and
	// 		is included in SQLite for  compatibility.
	//
	// `keyword`	A keyword enclosed in grave accents (ASCII
	// 		code 96) is an identifier. This is not standard SQL.
	// 		This quoting mechanism is used  by MySQL and is
	//		included in SQLite for compatibility.
	//
	// Sqlite enforces quoted string literals as identifiers based on
	// context
	EncodeIdentifier(pIdentifier string) string

	TransformTypeDeclaration(pColumn Column) string
}

The Dialect interface performs sql syntax modification to conform to the differences in implementations of the SQL standard. Initially the Dialect will be made with the differences of Sqlite3 in mind. Will be expanded in the future.

type DialectEncoder

type DialectEncoder (func(string) string)

type Domain

type Domain interface {
	ModelName() ModelName
}

Domain is the skeleton interface for a Model. The metadata tied to a Model is based on its domain name. A ModelName is derived from the package path and the standard name used to access a type in a package.

type DomainModel

type DomainModel struct {
	Domain
	Interface interface{}
}

type Entity

type Entity interface {

	// Should return an ActiveRecordDAO interface instance
	// of the main DAO
	ActiveRecord() ActiveRecordDAO

	// Returns the Entity's ModelName which represents its
	// domain or type
	ModelName() ModelName

	// Returns the model address so it can be used as
	// an ActiveRecord
	Model() Model

	// Each creation of a Model requires its own Entity
	// Creating a new Entity is based on the Domain's
	// default Entity for the Model which is created
	// through the NewEntity func passed at GEM startup.
	// The creation links the new Domain Entity with a
	// Model instance allowing database functions to be
	// performed on it.
	New(pModel Model) Entity

	// Insert passes the Model address to the the ModelDAO
	// service for persisting into the data-store
	Insert() Result

	// Save should update an already managed Model into
	// the data-store
	Save() Result

	// Delete should destroy and remove the Model from
	// the data-store
	Delete() Result

	// Metadata gets a copy of the Model's metadata
	Metadata() ModelMetadata

	// String returns a string representation of the Model
	String() string
}

The Entity interface is used to provide ActiveRecord and DAO access to a Model instance.

func NewEntity

func NewEntity(pModelName ModelName) Entity

Pass this function into the Gem to create all base Entities for each Model

type Execor

type Execor interface {
	// Retrieve the statement required for the database work
	// TODO handle discons
	ExecorStmt(pModel ModelName, pNamedStmt string) *sql.Stmt
}

type Float64

type Float64 struct {
	Float64 *float64
}

Float64 represents an int64 that may be null. Float64 implements the Scanner interface so It can be used as a scan destination, similar to sql.NullString.

func NewFloat64

func NewFloat64(p float64) Float64

Convenience constructor for an Float64

func (*Float64) A

func (o *Float64) A(p float64)

Convenience setting method

func (Float64) Kind

func (o Float64) Kind() reflect.Kind

Returns the primitive type

func (*Float64) Scan

func (o *Float64) Scan(pValue interface{}) error

Float64 the Scanner interface.

func (Float64) String

func (o Float64) String() string

Prints the value

func (Float64) Value

func (o Float64) Value() (driver.Value, error)

Float64 implements the driver Valuer interface.

type Gem

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

Go entity manager This struct acts as a mediator between Models and a sql.DB

func GEM

func GEM(o StartArgs) *Gem

func GetGem

func GetGem() Gem

Retrieve a copy of Gem

func (*Gem) Begin

func (o *Gem) Begin(fAction Action) *Txn
result, success := gemInstance.New((func(t Transaction)Result{
		person := domain.NewPerson()
		person.SetKey(190)
		person.Name.Set(name)
		person.Save()
		person = NewPerson()
		person.SetKey(191)
		person.Name.Set("Doong Gong Sum")
		return t.Persist(person)
	})).Go()

func (Gem) Exec

func (o Gem) Exec(pSql Sql, pArgs ...interface{}) (sql.Result, error)

TODO determine requirement error wrapping?

func (Gem) Metadata

func (o Gem) Metadata(pModelName ModelName) ModelMetadata

Gets a copy of the metadata associated with the Model which is identified by its ModelName

func (Gem) Query

func (o Gem) Query(pModelName ModelName, pSql Sql) ([]Model, error)

Runs a standard Db query which expects a slice of Models as a result, Will take any Sql interface and the ModelName to identify Model

func (Gem) QueryRow

func (o Gem) QueryRow(pModelName ModelName, pSql Sql, pArgs ...interface{}) Model

Runs a standard Db query which expects a Model as a result, Will take any Sql interface and the ModelName to identify Model TODO investigate do not support keyword as identifiers it's easier

type GenerationType

type GenerationType int
const (
	AUTO GenerationType = iota
	INCREMENT
	TABLE
	IDENTITY
	SEQUENCE
)

type Int64

type Int64 struct {
	Int64 *int64
}

Int64 represents an int64 that may be null. Int64 implements the Scanner interface so It can be used as a scan destination, similar to sql.NullString.

func NewInt64

func NewInt64(p int64) Int64

Convenience constructor for an Int64

func (*Int64) A

func (o *Int64) A(p int64)

Convenience setting method

func (*Int64) Assign

func (o *Int64) Assign(p int64)

Convenience setting method

func (Int64) Interface

func (o Int64) Interface() interface{}

func (Int64) Kind

func (o Int64) Kind() reflect.Kind

Returns the primitive type

func (Int64) Primitive

func (o Int64) Primitive() int64

Returns the primitive value of Int64 if nil returns 0 Same as Primitive()

func (*Int64) Scan

func (o *Int64) Scan(pValue interface{}) error

Int64 implements the Scanner interface.

func (Int64) String

func (o Int64) String() string

Prints the value

func (Int64) Value

func (o Int64) Value() (driver.Value, error)

Int64 implements the driver Valuer interface.

type Key

type Key interface {
	Opal
}

Key is a special type of opal.Opal

type KeyColumn

type KeyColumn struct {
	Auto bool
	Type GenerationType
}

type KeyField

type KeyField struct {
	Name      string
	TypeName  string
	Index     int
	Tag       string
	Kind      string
	Primitive string
}

type Mapper

type Mapper interface {
	Map() map[string]*interface{}
}

type Model

type Model interface {

	// A Model must implement the Entity interface.
	// This is achieved by Embedding the Entity implementation
	// into the Model implementation.
	Entity

	// It also retrieves a function to create the Models domain
	// specific DAO. This object can be used to perform tasks
	// associated with the Models domain rather than a single instance.
	Gather(pMetadata *ModelMetadata) (ModelName, *Entity, func(*ModelIDAO) ModelDAO)

	// ScanInto should return a new Model which can interact with
	// the base DAO system and addresses to its columns so data
	// can be scanned into it.
	ScanInto() (Model, []interface{})

	// Returns all columns' primary keys which can be scanned
	// into.
	Keys() []interface{}

	// Returns all columns' non primary keys which can be scanned
	// into.
	Parameters() []interface{}
}

A Model is the interface type which can represent any object that can be stored as a Database store item

type ModelArgs

type ModelArgs func(Model) []interface{}

Any function which takes a Model and returns an arg slice

type ModelDAO

type ModelDAO interface {
	Opal
	ActiveRecordDAO

	// Find all models within the domain
	FindAllModels() []Model

	// Find a specific Model using its keys
	FindModel(pKeys ...interface{}) Model

	// Create a Sql Builder for the specified Model
	SqlBuilder() *SqlBuilder

	// Returns the ModelName associated with this instance
	Model() ModelName
}

ModelDAO acts a data provider for a Model's domain Methods are

type ModelHook

type ModelHook func() error

ModelHook can be used by a Model implementation to do a specific task on one of the pre defined sql execution events. A Model must implement one of the Hook interfaces below for the ModelHook function to run during Model related execution.

type ModelIDAO

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

ModelIDAO Implements ModelDAO

func (*ModelIDAO) Delete

func (o *ModelIDAO) Delete(pModel Model) Result

func (*ModelIDAO) ExecorStmt

func (o *ModelIDAO) ExecorStmt(pModel ModelName, pNamedStmt string) *sql.Stmt

func (ModelIDAO) FindAllModels

func (o ModelIDAO) FindAllModels() []Model

func (ModelIDAO) FindModel

func (o ModelIDAO) FindModel(pKeys ...interface{}) Model

TODO better key solution

func (ModelIDAO) Gem

func (o ModelIDAO) Gem() Gem

TODO betterway to handle DAO

func (*ModelIDAO) Insert

func (o *ModelIDAO) Insert(pModel Model) Result

TODO find why insert prepared statement does not work TODO fix persis gets a primary key unique constraint error

func (ModelIDAO) Kind

func (ModelIDAO) Kind() reflect.Kind

Opal partially implements the opal OPAL interface

func (ModelIDAO) Model

func (o ModelIDAO) Model() ModelName

func (*ModelIDAO) Save

func (o *ModelIDAO) Save(pModel Model) Result

func (*ModelIDAO) SqlBuilder

func (o *ModelIDAO) SqlBuilder() *SqlBuilder

type ModelMetadata

type ModelMetadata struct {
	Model

	Service ModelDAO
	// contains filtered or unexported fields
}

func NewMetadata

func NewMetadata(pModel Model, pType reflect.Type) *ModelMetadata

Hold special data about a domain object model

func (*ModelMetadata) AddColumn

func (o *ModelMetadata) AddColumn(pField string, pIndex int, pColumn Column, pKind reflect.Kind)

TODO

func (*ModelMetadata) AddKey

func (o *ModelMetadata) AddKey(pField string, pIndex int, pColumn Column, pKind reflect.Kind)

TODO

func (*ModelMetadata) AddTable

func (o *ModelMetadata) AddTable(pTable Table, pKeyFieldNames ...string)

TODO

func (ModelMetadata) Column

func (o ModelMetadata) Column(pField string) Column

Get the column metadata by the domains field name

func (ModelMetadata) ColumnByFieldIndex

func (o ModelMetadata) ColumnByFieldIndex(pIndex int) Column

Get the column metadata by the domains field index

func (ModelMetadata) ColumnByIndex

func (o ModelMetadata) ColumnByIndex(index int) Column

Get the column metadata by its natural index

func (*ModelMetadata) ColumnListWithConstraints

func (o *ModelMetadata) ColumnListWithConstraints(pBuilder *SqlBuilder, fDialect DialectEncoder) *SqlBuilder

TODO

func (ModelMetadata) Columns

func (o ModelMetadata) Columns() []Column

Get the columns metadata

func (*ModelMetadata) ColumnsBindList

func (o *ModelMetadata) ColumnsBindList(pBuilder *SqlBuilder, fDialect DialectEncoder) *SqlBuilder

Adds columns onto a sql builder in the form :Name, :Name,... or ?, ?... // TODO

func (*ModelMetadata) ColumnsList

func (o *ModelMetadata) ColumnsList(pBuilder *SqlBuilder, fDialect DialectEncoder) *SqlBuilder

TODO

func (*ModelMetadata) ColumnsListEqualsColumnsBindList

func (o *ModelMetadata) ColumnsListEqualsColumnsBindList(pBuilder *SqlBuilder, fDialect DialectEncoder) *SqlBuilder

TODO

func (*ModelMetadata) KeyListEqualsKeyBindList

func (o *ModelMetadata) KeyListEqualsKeyBindList(pBuilder *SqlBuilder, fDialect DialectEncoder) *SqlBuilder

TODO

func (*ModelMetadata) NonKeyListEqualsNonKeyBindList

func (o *ModelMetadata) NonKeyListEqualsNonKeyBindList(pBuilder *SqlBuilder, fDialect DialectEncoder) *SqlBuilder

sqlite seems to ignore incorrect set pk bindings when updating TODO need to ignore primary keys columns

func (*ModelMetadata) ReplaceColumnIdentifiers

func (o *ModelMetadata) ReplaceColumnIdentifiers(sql string, fDialect DialectEncoder) string

TODO

func (*ModelMetadata) ReplaceTableIdentifiers

func (o *ModelMetadata) ReplaceTableIdentifiers(sql string, fDialect DialectEncoder) string

TODO

func (ModelMetadata) Table

func (o ModelMetadata) Table() Table

Get the columns metadata

func (ModelMetadata) Type

func (o ModelMetadata) Type() reflect.Type

Get the type of the entity domain parent

type ModelName

type ModelName string

A ModelName is an identifying string specific to a Model. It must be unique across all entities e.g: domain.Person

func (ModelName) Name

func (m ModelName) Name() string

Name splits a model name from its package and returns the Model only name as a string This should return the implementations struct name

func (ModelName) String

func (m ModelName) String() string

Casts a ModelName into a string

type ModelQueries

type ModelQueries interface {
	NamedQueries() []PreparedQuery
	DerivedQueries() []PreparedQuery
}

type ModelTemplate

type ModelTemplate struct {
	Version string
	Date    string
	Time    string
	Types   map[string]*TemplateType
}

Some rules 1: Primary keys if not one of the four base types will be an embedded type where only one param will be generated. 2: Compound keys which are expanded will be of the four base

base types and their primitives will be expanded into the

parameters.

type ModifyDB

type ModifyDB (func(ModelName, Model) (Result, error))

type Opal

type Opal interface {
	Kind() reflect.Kind
	// contains filtered or unexported methods
}

Interface Opal acts as a shoe horn for valid types in a model

type OpalEntity

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

OpalEntity implements the Entity interface If you require your own implementation you can supply Gem a function through which to create the Model embeddable instances of the Entity.

func (OpalEntity) ActiveRecord

func (o OpalEntity) ActiveRecord() ActiveRecordDAO

func (*OpalEntity) Delete

func (o *OpalEntity) Delete() Result

func (*OpalEntity) Insert

func (o *OpalEntity) Insert() Result

func (*OpalEntity) Metadata

func (o *OpalEntity) Metadata() ModelMetadata

func (OpalEntity) Model

func (o OpalEntity) Model() Model

func (OpalEntity) ModelName

func (o OpalEntity) ModelName() ModelName

func (OpalEntity) New

func (o OpalEntity) New(pModel Model) Entity

TODO shrink use of instances here if possible heavy on performance

func (*OpalEntity) Save

func (o *OpalEntity) Save() Result

func (*OpalEntity) String

func (o *OpalEntity) String() string

type OpalMagic

type OpalMagic int

A simple type to return the global identifying opal

type OpalSql

type OpalSql string

Future type for using when the opal sql has more of its own nuances

func (OpalSql) String

func (o OpalSql) String() string

type PostDelete

type PostDelete interface {
	PostDeleteHook() error
}

Post delete hook interface

type PostInsert

type PostInsert interface {
	PostInsertHook() error
}

Post insert hook interface

type PostUpdate

type PostUpdate interface {
	PostUpdateHook() error
}

Post update hook interface

type PreDelete

type PreDelete interface {
	PreDeleteHook() error
}

Pre delete hook interface

type PreInsert

type PreInsert interface {
	PreInsertHook() error
}

Pre insert hook interface

type PreUpdate

type PreUpdate interface {
	PreUpdateHook() error
}

Pre update hook interface

type PreparedQuery

type PreparedQuery interface {
}

type Result

type Result struct {
	sql.Result
	Error error
}

Result is a wrapper around a sql.Result and any affiliated error. It is used to simplify the API TODO change package for Result as its associated to DAO

func (Result) String

func (o Result) String() string

type Rows

type Rows struct {
	*sql.Rows // TODO explore embedded is wasteful?
}

type Select

type Select func(pTx Transaction) ([]Model, error)

type Slice

type Slice struct {
	Slice []byte
}

Slice implements the Scanner interface so It can be used as a scan destination, similar to sql.NullString.

func NewSlice

func NewSlice(p []byte) Slice

Convenience constructor for a Slice

func (*Slice) A

func (o *Slice) A(p []byte)

Convenience setting method

func (Slice) Kind

func (o Slice) Kind() reflect.Kind

Returns the primitive type

func (*Slice) Scan

func (o *Slice) Scan(pValue interface{}) error

Slice implements the sql.Scanner interface.

func (Slice) String

func (o Slice) String() string

Prints the value

func (*Slice) Value

func (o *Slice) Value() (driver.Value, error)

Slice implements the driver Valuer interface.

type Sql

type Sql interface {
	String() string
}

type SqlBuilder

type SqlBuilder struct {
	*ModelMetadata
	Dialect
	bytes.Buffer
}

func (*SqlBuilder) Add

func (o *SqlBuilder) Add(p string) *SqlBuilder

func (*SqlBuilder) Create

func (o *SqlBuilder) Create() *SqlBuilder

func (*SqlBuilder) Delete

func (o *SqlBuilder) Delete() *SqlBuilder

func (*SqlBuilder) Do

func (o *SqlBuilder) Do(...interface{}) *SqlBuilder

func (*SqlBuilder) Insert

func (o *SqlBuilder) Insert() *SqlBuilder

func (*SqlBuilder) Select

func (o *SqlBuilder) Select(pColumns ...string) *SqlBuilder

func (*SqlBuilder) Sql

func (o *SqlBuilder) Sql() Sql

func (*SqlBuilder) Truncate

func (o *SqlBuilder) Truncate(pInt int) *SqlBuilder

func (*SqlBuilder) Update

func (o *SqlBuilder) Update() *SqlBuilder

func (*SqlBuilder) Values

func (o *SqlBuilder) Values() *SqlBuilder

func (*SqlBuilder) Where

func (o *SqlBuilder) Where(pMap Mapper) *SqlBuilder

func (*SqlBuilder) WhereAll

func (o *SqlBuilder) WhereAll() *SqlBuilder

func (*SqlBuilder) WherePk

func (o *SqlBuilder) WherePk() *SqlBuilder

func (*SqlBuilder) With

func (o *SqlBuilder) With(fBuild SqlBuilderDialectEncoder, fDialect DialectEncoder) *SqlBuilder

type SqlBuilderDialectEncoder

type SqlBuilderDialectEncoder func(*SqlBuilder, DialectEncoder) *SqlBuilder

type StartArgs

type StartArgs struct {
	BaseModel    BaseModel
	DB           *sql.DB
	Dialect      Dialect
	CreateEntity func(ModelName) Entity
	Id           *OpalMagic
}

type StmtExec

type StmtExec func(...interface{}) (*sql.Result, error)

type StmtQuery

type StmtQuery func(...interface{}) (*sql.Rows, error)

type StmtQueryRow

type StmtQueryRow func(...interface{}) *sql.Row

type String

type String struct {
	Str *string
}

String represents an int64 that may be null. String implements the Scanner interface so It can be used as a scan destination, similar to sql.NullString.

func NewString

func NewString(p string) String

Convenience constructor for a String

func (*String) A

func (o *String) A(p string)

Convenience setting method

func (String) Kind

func (o String) Kind() reflect.Kind

Returns the primitive type

func (*String) Scan

func (o *String) Scan(pValue interface{}) error

String implements the sql.Scanner interface.

func (String) String

func (o String) String() string

Prints the value

func (String) Value

func (o String) Value() (driver.Value, error)

String implements the driver Valuer interface.

type T

type T struct{}

An embeddable struct with which to create your own types

func (T) Kind

func (T) Kind() reflect.Kind

T partially implements the opal.Opal interface

type Table

type Table struct {
	Name string
	Key  []string
}

TODO

type Tag

type Tag string

A StructTag is the tag string in a struct field.

By convention, tag strings are a concatenation of optionally space-separated key:"value" pairs. Each key is a non-empty string consisting of non-control characters other than space (U+0020 ' '), quote (U+0022 '"'), and colon (U+003A ':'). Each value is quoted using U+0022 '"' characters and Go string literal syntax.

func ExtractOpalTags

func ExtractOpalTags(pStructTag reflect.StructTag) Tag

func (Tag) Get

func (tag Tag) Get(key string) string

Get returns the value associated with key in the tag string. If there is no such key in the tag, Get returns the empty string. If the tag does not have the conventional format, the value returned by Get is unspecified.

type TemplateField

type TemplateField struct {
	Name      string
	Index     int
	Tag       string
	Kind      string
	Primitive string
}

type TemplateType

type TemplateType struct {
	Domain
	Version    string
	Date       string
	Time       string
	Receiver   string
	Model      string
	DAOName    string
	Path       string
	Package    string
	ImportName string
	Table      string
	Keys       []KeyField
	Columns    []TemplateField
}

type Time

type Time struct {
	*time.Time
}

Time represents an time.Time that may be null. Time implements the Scanner interface so It can be used as a scan destination, similar to sql.NullString.

func NewTime

func NewTime(p time.Time) Time

Convenience constructor for an Bool

func (*Time) A

func (o *Time) A(p time.Time)

Convenience setting method

func (Time) Kind

func (o Time) Kind() reflect.Kind

Returns the primitive type

func (*Time) Scan

func (o *Time) Scan(pValue interface{}) error

Time implements the sql.Scanner interface.

func (Time) String

func (o Time) String() string

Prints the value

func (Time) Value

func (o Time) Value() (driver.Value, error)

Time implements the driver Valuer interface.

type Transaction

type Transaction struct {
	*Txn
}

Transaction is a wrapper of a *Txn for building Transactions. It is used to simplify Transaction building from a user perspective. t Transaction is much easier to remember than t *Txn

type TxArgs

type TxArgs func(pTx Transaction, pArgs interface{}) error

type Txn

type Txn struct {

	//Embedded so Txn behaves like a standard Tx
	*sql.Tx
	// contains filtered or unexported fields
}

Txn is a sql.Tx wrapper which holds the action to run and its result It also carries a reference to the current Gem.

func (*Txn) Create

func (o *Txn) Create(pModel Model, pArgs Args) Result

Persist will insert the Model within a Transaction. Call this within a Txn func Action

func (*Txn) Delete

func (o *Txn) Delete(pModel Model) Result

Delete will delete the Model within a Transaction. Call this within a Txn func Action

func (*Txn) Exec

func (o *Txn) Exec(pSql Sql, pArgs ...interface{}) Result

func (*Txn) ExecorStmt

func (o *Txn) ExecorStmt(pModelName ModelName, pNamedStmt string) *sql.Stmt

func (*Txn) Go

func (o *Txn) Go() (result Result, success bool)

Go runs the Transaction it has in from Gem.Begin Begin Running Go will defer control of Rollback and Commit functionality to the system. If required a user can manually run a transaction using the *sql.DB connection. Returns the result and whether the transaction was successful

func (*Txn) Insert

func (o *Txn) Insert(pModel Model) Result

Persist will insert the Model within a Transaction. Call this within a Txn func Action

func (*Txn) Update

func (o *Txn) Update(pModel Model) Result

Update will update the Model within a Transaction. Call this within a Txn func Action

type Type

type Type interface {
	Scan(interface{}) error
	Interface() interface{}
	Value() (driver.Value, error)
	String() string
}

type Validation

type Validation interface {
}

Directories

Path Synopsis
Stringer is a tool to automate the creation of methods that satisfy the fmt.Stringer interface.
Stringer is a tool to automate the creation of methods that satisfy the fmt.Stringer interface.

Jump to

Keyboard shortcuts

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