dbobj

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2020 License: BSD-2-Clause Imports: 7 Imported by: 0

README

dbobj GoDoc

A lightweight ORM with sql code generation for speed

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoKeyField is returned for tables without primary key identified
	ErrNoKeyField = errors.New("table has no key field")

	// ErrKeyMissing is returned when key value is not set
	ErrKeyMissing = errors.New("key is not set")

	ErrNilWritePointers = errors.New("nil record dest members")
)

Functions

This section is empty.

Types

type Common

type Common interface {
	Columns() []string
	Next() bool
	Scan(...interface{}) error
}

Common Rows object between rqlite and /pkg/database/sql

type DBList

type DBList interface {
	QueryString(extra string) string
	Receivers() []interface{}
}

DBList is the interface for a list of db objects

type DBObject

type DBObject interface {
	// TableName is the name of the sql table
	TableName() string

	// KeyFields are the names of the table fields
	// comprising the primary id
	//KeyFields() []string
	KeyField() string

	// KeyNames are the struct names of the
	// primary id fields
	//KeyNames() []string
	KeyName() string

	// Names returns the struct element names
	Names() []string

	// SelectFields returns the comma separated
	// list of fields to be selected
	SelectFields() string

	// InsertFields returns the comma separated
	// list of fields to be selected
	InsertFields() string

	// Key returns the int64 id value of the object
	Key() int64

	// SetID updates the id of the object
	SetID(int64)

	// InsertValues returns the values of the object to be inserted
	InsertValues() []interface{}

	// InsertValues returns the values of the object to be updated
	UpdateValues() []interface{}

	// MemberPointers  returns a slice of pointers to values
	// for the db scan function
	MemberPointers() []interface{}

	// ModifiedBy returns the user id and timestamp of when the object was last modified
	ModifiedBy(int64, time.Time)
}

DBObject provides methods for object storage The functions are generated for each object annotated accordingly

type DBS

type DBS interface {
	Query(fn SetHandler, query string, args ...interface{}) error
	Exec(query string, args ...interface{}) (RowsAffected, LastInsertID int64, err error)
}

DBS is an abstracted database interface, intended to work with both rqlite and regular sql.DB connections

type DBU

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

DBU is a DatabaseUnit

func NewDBU

func NewDBU(file string, init bool, opener SQLDB) (DBU, error)

NewDBU returns a new DBU

func (DBU) Add

func (db DBU) Add(o DBObject) error

Add new object to datastore

func (DBU) Delete

func (db DBU) Delete(o DBObject) error

Delete object from datastore

func (DBU) DeleteByID

func (db DBU) DeleteByID(o DBObject, id interface{}) error

DeleteByID object from datastore by id

func (DBU) Find

func (db DBU) Find(o DBObject, keys map[string]interface{}) error

Find loads an object matching the given keys

func (DBU) FindBy

func (db DBU) FindBy(o DBObject, key string, value interface{}) error

FindBy loads an object matching the given key/value

func (DBU) FindByID

func (db DBU) FindByID(o DBObject, value interface{}) error

FindByID loads an object based on a given ID

func (DBU) FindSelf

func (db DBU) FindSelf(o DBObject) error

FindSelf loads an object based on it's current ID

func (DBU) List

func (db DBU) List(list DBList) error

List objects from datastore

func (DBU) ListQuery

func (db DBU) ListQuery(list DBList, extra string) error

ListQuery updates a list of objects TODO: handle args/vs no args for rqlite

func (DBU) Replace

func (db DBU) Replace(o DBObject) error

Replace will replace an existing object in datastore

func (DBU) Save

func (db DBU) Save(o DBObject) error

Save modified object in datastore

func (DBU) SetLogger

func (db DBU) SetLogger(logger *log.Logger)

SetLogger sets the logger for the db

type SQLDB

type SQLDB func(string) (*sql.DB, error)

SQLDB is a common interface for opening an sql db

type SetHandler

type SetHandler func() []interface{}

SetHandler returns a slice of value pointer interfaces If there are no values to set it returns a nil instead

Directories

Path Synopsis
dbgen is a tool to automate the creation of create/update/delete methods that satisfy the github.com/paulstuart/dbobj.DBObject interface.
dbgen is a tool to automate the creation of create/update/delete methods that satisfy the github.com/paulstuart/dbobj.DBObject interface.

Jump to

Keyboard shortcuts

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