gorpmapper

package
v0.54.1 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: BSD-3-Clause Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ViolateForeignKeyPGCode is the pg code when violating foreign key
	ViolateForeignKeyPGCode = "23503"

	// ViolateUniqueKeyPGCode is the pg code when duplicating unique key
	ViolateUniqueKeyPGCode = "23505"

	// StringDataRightTruncation is raisedalue is too long for varchar.
	StringDataRightTruncation = "22001"
)
View Source
const (
	KeyEcnryptionIdentifier = "db-crypt"
)
View Source
const (
	KeySignIdentifier = "db-sign"
)

Constant for gorp mapping.

Variables

View Source
var GetOptions = struct {
	WithDecryption GetOptionFunc
}{
	WithDecryption: getEncryptedData,
}

Functions

func And

func And(es ...string) string

And returns a new AND expression from given ones.

func ToQueryString

func ToQueryString(target interface{}) string

ToQueryString returns a comma separated list of given ids.

Types

type ArgsMap

type ArgsMap map[string]interface{}

ArgsMap represents the map of named sql args.

func (ArgsMap) Merge

func (a ArgsMap) Merge(other ArgsMap) ArgsMap

Merge returns a merged map from current and another.

type CanonicalForm

type CanonicalForm string

func (*CanonicalForm) Bytes

func (f *CanonicalForm) Bytes() []byte

func (*CanonicalForm) String

func (f *CanonicalForm) String() string

type CanonicalForms

type CanonicalForms []CanonicalForm

func (CanonicalForms) Latest

type Canonicaller

type Canonicaller interface {
	Canonical() CanonicalForms
}

Canonicaller returns a byte array that represent its data.

type EncryptedField

type EncryptedField struct {
	Name   string
	Column string
	Extras []string
}

type GetOptionFunc

type GetOptionFunc func(context.Context, *Mapper, gorp.SqlExecutor, interface{}) error

type IDs

type IDs pq.Int64Array

type Mapper

type Mapper struct {
	Mapping map[string]TableMapping

	CanonicalFormTemplates struct {
		M map[string]*template.Template
		L sync.RWMutex
	}
	// contains filtered or unexported fields
}

Mapping is the global var for all registered mapping

func New

func New() *Mapper

func (*Mapper) CheckSignature

func (m *Mapper) CheckSignature(i Canonicaller, sig []byte) (bool, error)

CheckSignature return true if a given signature is valid for given object.

func (*Mapper) ConfigureKeys

func (m *Mapper) ConfigureKeys(signatureKeys, encryptionKeys *[]keyloader.KeyConfig) error

func (*Mapper) Decrypt

func (m *Mapper) Decrypt(src []byte, dest interface{}, extra []interface{}) error

func (*Mapper) Delete

func (m *Mapper) Delete(db gorp.SqlExecutor, i interface{}) error

Delete value in given db.

func (*Mapper) Encrypt

func (m *Mapper) Encrypt(src interface{}, dst *[]byte, extra []interface{}) error

func (*Mapper) Get

func (m *Mapper) Get(ctx context.Context, db gorp.SqlExecutor, q Query, i interface{}, opts ...GetOptionFunc) (bool, error)

Get a value from database.

func (*Mapper) GetAll

func (m *Mapper) GetAll(ctx context.Context, db gorp.SqlExecutor, q Query, i interface{}, opts ...GetOptionFunc) error

GetAll values from database.

func (*Mapper) GetInt

func (m *Mapper) GetInt(db gorp.SqlExecutor, q Query) (int64, error)

GetInt a value from database.

func (*Mapper) GetTableMapping

func (m *Mapper) GetTableMapping(i interface{}) (TableMapping, bool)

func (*Mapper) Insert

func (m *Mapper) Insert(db gorp.SqlExecutor, i interface{}) error

Insert value in given db.

func (*Mapper) InsertAndSign

func (m *Mapper) InsertAndSign(ctx context.Context, db gorp.SqlExecutor, i Canonicaller) error

InsertAndSign a data in database, given data should implement canonicaller interface.

func (*Mapper) ListCanonicalFormsByEntity

func (m *Mapper) ListCanonicalFormsByEntity(db gorp.SqlExecutor, entity string) ([]sdk.CanonicalFormUsage, error)

func (*Mapper) ListEncryptedEntities

func (m *Mapper) ListEncryptedEntities() []string

func (*Mapper) ListSignedEntities

func (m *Mapper) ListSignedEntities() []string

func (*Mapper) ListTupleByCanonicalForm

func (m *Mapper) ListTupleByCanonicalForm(db gorp.SqlExecutor, entity, signer string) ([]string, error)

func (*Mapper) ListTuplesByEntity

func (m *Mapper) ListTuplesByEntity(db gorp.SqlExecutor, entity string) ([]string, error)

func (*Mapper) LoadAndLockTupleByPrimaryKey

func (m *Mapper) LoadAndLockTupleByPrimaryKey(ctx context.Context, db gorp.SqlExecutor, entity string, pk interface{}, opts ...GetOptionFunc) (interface{}, error)

func (*Mapper) LoadTupleByPrimaryKey

func (m *Mapper) LoadTupleByPrimaryKey(ctx context.Context, db gorp.SqlExecutor, entity string, pk interface{}, opts ...GetOptionFunc) (interface{}, error)

func (*Mapper) NewTableMapping

func (m *Mapper) NewTableMapping(target interface{}, name string, autoIncrement bool, keys ...string) TableMapping

NewTableMapping initialize a TableMapping.

func (*Mapper) Register

func (m *Mapper) Register(ms ...TableMapping)

Register intialiaze gorp mapping

func (*Mapper) RollEncryptedTupleByPrimaryKey

func (m *Mapper) RollEncryptedTupleByPrimaryKey(ctx context.Context, db gorp.SqlExecutor, entity string, pk interface{}) error

func (*Mapper) RollSignedTupleByPrimaryKey

func (m *Mapper) RollSignedTupleByPrimaryKey(ctx context.Context, db SqlExecutorWithTx, entity string, pk interface{}) error

func (*Mapper) Update

func (m *Mapper) Update(db gorp.SqlExecutor, i interface{}) error

Update value in given db.

func (*Mapper) UpdateAndSign

func (m *Mapper) UpdateAndSign(ctx context.Context, db gorp.SqlExecutor, i Canonicaller) error

UpdateAndSign a data in database, given data should implement canonicaller interface.

func (*Mapper) UpdateColumns

func (m *Mapper) UpdateColumns(db gorp.SqlExecutor, i interface{}, columnFilter gorp.ColumnFilter) error

func (*Mapper) UpdateColumnsAndSign

func (m *Mapper) UpdateColumnsAndSign(ctx context.Context, db gorp.SqlExecutor, i Canonicaller, colFilter gorp.ColumnFilter) error

UpdateColumnsAndSign a data in database, given data should implement canonicaller interface.

type Query

type Query struct {
	Query     string
	Arguments []interface{}
}

Query to get gorp entities in database.

func NewQuery

func NewQuery(q string) Query

NewQuery returns a new query from given string request.

func (Query) Args

func (q Query) Args(as ...interface{}) Query

Args store query arguments.

func (Query) Limit

func (q Query) Limit(i int) Query

func (Query) String

func (q Query) String() string

type SensitiveJsonData added in v0.52.0

type SensitiveJsonData struct {
	Data string
}

type Signed

type Signed interface {
	GetSignature() []byte
}

type SignedEntity

type SignedEntity struct {
	Signature []byte `json:"-" db:"sig"`
}

SignedEntity struct for signed entity stored in database.

func (SignedEntity) GetSignature

func (s SignedEntity) GetSignature() []byte

type SqlExecutorWithTx

type SqlExecutorWithTx interface {
	gorp.SqlExecutor
	Commit() error
	Rollback() error
}

type TableMapping

type TableMapping struct {
	Target          interface{}
	Name            string
	AutoIncrement   bool
	SignedEntity    bool
	Keys            []string
	EncryptedEntity bool
	EncryptedFields []EncryptedField
}

TableMapping represents a table mapping with gorp

type TestEncryptedData

type TestEncryptedData struct {
	SignedEntity
	ID                   int64             `db:"id"`
	Data                 string            `db:"data"`
	SensitiveData        string            `db:"sensitive_data" gorpmapping:"encrypted,Data"`
	AnotherSensitiveData string            `db:"another_sensitive_data" gorpmapping:"encrypted,ID,Data"`
	SensitiveJsonData    SensitiveJsonData `db:"sensitive_json_data" gorpmapping:"encrypted,ID"`
}

func (TestEncryptedData) Canonical

func (e TestEncryptedData) Canonical() CanonicalForms

Jump to

Keyboard shortcuts

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