Help us shape the future of Go! Take the 2026 Go Developer Survey

gorpmapper

package
v0.57.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: BSD-3-Clause Imports: 30 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 (
	KeyEncryptionIdentifier = "db-crypt"
)
View Source
const (
	KeySignIdentifier = "db-sign"
)

Constant for gorp mapping.

Variables

View Source
var GetAllOptions = struct {
	WithDecryption GetAllOptionFunc
}{
	WithDecryption: getEncryptedSliceData,
}
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 GetSigner added in v0.55.2

func GetSigner(f *CanonicalForm) string

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 GetAllOptionFunc added in v0.55.2

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

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) CheckSignatureUncap added in v0.55.2

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

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) DecryptUncap added in v0.55.2

func (m *Mapper) DecryptUncap(src []byte, dest interface{}, extra []interface{}) (int, 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 ...GetAllOptionFunc) 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) InfoTupleByPrimaryKey added in v0.55.2

func (m *Mapper) InfoTupleByPrimaryKey(ctx context.Context, db gorp.SqlExecutor, entity string, pk string) (*sdk.DatabaseEntityInfo, error)

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 SqlExecutorWithTx, 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.DatabaseCanonicalForm, error)

func (*Mapper) ListTuplesByCanonicalForm added in v0.55.2

func (m *Mapper) ListTuplesByCanonicalForm(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) RollTupleByPrimaryKey added in v0.55.2

func (m *Mapper) RollTupleByPrimaryKey(ctx context.Context, db SqlExecutorWithTx, entity string, pk string) (*sdk.DatabaseEntityInfo, 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 SqlExecutorWithTx, 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 SqlExecutorWithTx, 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