dalgorm

package
v0.0.0-...-7d3b672 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(encryptionSecret string)

Init the encdec serializer

func ToDatabaseMap

func ToDatabaseMap(tableName string, m map[string]any) map[string]any

ToDatabaseMap convert the map to a format that can be inserted into a SQL database

Types

type ColumnType

type ColumnType string
const (
	Varchar ColumnType = "varchar(255)"
	Text    ColumnType = "text"
	Int     ColumnType = "bigint"
	Time    ColumnType = "timestamp"
	Float   ColumnType = "float"
)

func (ColumnType) String

func (c ColumnType) String() string

type Dalgorm

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

Dalgorm implements the dal.Dal interface with gorm

func NewDalgorm

func NewDalgorm(db *gorm.DB) *Dalgorm

NewDalgorm creates a *Dalgorm

func (*Dalgorm) AddColumn

func (d *Dalgorm) AddColumn(table, columnName string, columnType dal.ColumnType) errors.Error

AddColumn add one column for the table

func (*Dalgorm) All

func (d *Dalgorm) All(dst interface{}, clauses ...dal.Clause) errors.Error

All loads matched rows from database to `dst`, USE IT WITH COUTIOUS!!

func (*Dalgorm) AllTables

func (d *Dalgorm) AllTables() ([]string, errors.Error)

AllTables returns all tables in the database

func (*Dalgorm) AutoMigrate

func (d *Dalgorm) AutoMigrate(entity interface{}, clauses ...dal.Clause) errors.Error

AutoMigrate runs auto migration for given models

func (*Dalgorm) Begin

func (d *Dalgorm) Begin() dal.Transaction

Begin create a new transaction

func (*Dalgorm) Count

func (d *Dalgorm) Count(clauses ...dal.Clause) (int64, errors.Error)

Count total records

func (*Dalgorm) Create

func (d *Dalgorm) Create(entity interface{}, clauses ...dal.Clause) errors.Error

Create insert record to database

func (*Dalgorm) CreateIfNotExist

func (d *Dalgorm) CreateIfNotExist(entity interface{}, clauses ...dal.Clause) errors.Error

CreateIfNotExist tries to create the record if not exist

func (*Dalgorm) CreateOrUpdate

func (d *Dalgorm) CreateOrUpdate(entity interface{}, clauses ...dal.Clause) errors.Error

CreateOrUpdate tries to create the record, or fallback to update all if failed

func (*Dalgorm) CreateWithMap

func (d *Dalgorm) CreateWithMap(entity interface{}, record map[string]interface{}) errors.Error

CreateWithMap insert record to database

func (*Dalgorm) Cursor

func (d *Dalgorm) Cursor(clauses ...dal.Clause) (dal.Rows, errors.Error)

Cursor returns a database cursor, cursor is especially useful when handling big amount of rows of data

func (*Dalgorm) CursorTx

func (d *Dalgorm) CursorTx(clauses ...dal.Clause) *gorm.DB

CursorTx FIXME ...

func (*Dalgorm) Delete

func (d *Dalgorm) Delete(entity interface{}, clauses ...dal.Clause) errors.Error

Delete records from database

func (*Dalgorm) Dialect

func (d *Dalgorm) Dialect() string

Dialect returns the dialect of the database

func (*Dalgorm) DropColumns

func (d *Dalgorm) DropColumns(table string, columnNames ...string) errors.Error

DropColumns drop one column from the table

func (*Dalgorm) DropIndexes

func (d *Dalgorm) DropIndexes(table string, indexNames ...string) errors.Error

DropIndexes drops indexes for specified table

func (*Dalgorm) DropTables

func (d *Dalgorm) DropTables(dst ...interface{}) errors.Error

DropTables drop multiple tables by Model Pointer or Table Name

func (*Dalgorm) Exec

func (d *Dalgorm) Exec(query string, params ...interface{}) errors.Error

Exec executes raw sql query

func (*Dalgorm) Fetch

func (d *Dalgorm) Fetch(cursor dal.Rows, dst interface{}) errors.Error

Fetch loads row data from `cursor` into `dst`

func (*Dalgorm) First

func (d *Dalgorm) First(dst interface{}, clauses ...dal.Clause) errors.Error

First loads first matched row from database to `dst`, error will be returned if no records were found

func (*Dalgorm) GetColumns

func (d *Dalgorm) GetColumns(dst dal.Tabler, filter func(columnMeta dal.ColumnMeta) bool) (cms []dal.ColumnMeta, _ errors.Error)

GetColumns FIXME ...

func (*Dalgorm) GetPrimaryKeyFields

func (d *Dalgorm) GetPrimaryKeyFields(t reflect.Type) []reflect.StructField

GetPrimaryKeyFields get the PrimaryKey from `gorm` tag

func (*Dalgorm) HasColumn

func (d *Dalgorm) HasColumn(table interface{}, columnName string) bool

HasColumn checks if column exists

func (*Dalgorm) HasTable

func (d *Dalgorm) HasTable(table interface{}) bool

HasTable checks if table exists

func (*Dalgorm) IsDuplicationError

func (d *Dalgorm) IsDuplicationError(err error) bool

IsDuplicationError checking if the sql error is not found.

func (*Dalgorm) IsErrorNotFound

func (d *Dalgorm) IsErrorNotFound(err error) bool

IsErrorNotFound checking if the sql error is not found.

func (*Dalgorm) Pluck

func (d *Dalgorm) Pluck(column string, dest interface{}, clauses ...dal.Clause) errors.Error

Pluck used to query single column

func (*Dalgorm) RawCursor

func (d *Dalgorm) RawCursor(query string, params ...interface{}) (*sql.Rows, errors.Error)

RawCursor (Deprecated) executes raw sql query and returns a database cursor

func (*Dalgorm) RenameColumn

func (d *Dalgorm) RenameColumn(table, oldColumnName, newColumnName string) errors.Error

RenameColumn renames column name for specified table

func (*Dalgorm) RenameTable

func (d *Dalgorm) RenameTable(oldName, newName string) errors.Error

RenameTable renames table name

func (*Dalgorm) Session

func (d *Dalgorm) Session(config dal.SessionConfig) dal.Dal

Session creates a new manual transaction for special scenarios

func (*Dalgorm) Update

func (d *Dalgorm) Update(entity interface{}, clauses ...dal.Clause) errors.Error

Update updates record

func (*Dalgorm) UpdateAllColumn

func (d *Dalgorm) UpdateAllColumn(entity interface{}, clauses ...dal.Clause) errors.Error

UpdateAllColumn updated all Columns of entity

func (*Dalgorm) UpdateColumn

func (d *Dalgorm) UpdateColumn(entityOrTable interface{}, columnName string, value interface{}, clauses ...dal.Clause) errors.Error

UpdateColumn allows you to update mulitple records

func (*Dalgorm) UpdateColumns

func (d *Dalgorm) UpdateColumns(entityOrTable interface{}, set []dal.DalSet, clauses ...dal.Clause) errors.Error

UpdateColumns allows you to update multiple columns of mulitple records

type DalgormTransaction

type DalgormTransaction struct {
	*Dalgorm
}

DalgormTransaction represents a gorm transaction which using the same underlying session for all queries

func (*DalgormTransaction) Commit

func (t *DalgormTransaction) Commit() errors.Error

Commit the transaction

func (*DalgormTransaction) Rollback

func (t *DalgormTransaction) Rollback() errors.Error

Rollback the transaction

type EncDecSerializer

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

EncDecSerializer is responsible for field encryption/decryption in Application Level Ref: https://gorm.io/docs/serializer.html

func (*EncDecSerializer) Scan

func (es *EncDecSerializer) Scan(ctx context.Context, field *schema.Field, dst reflect.Value, dbValue interface{}) (err error)

Scan implements serializer interface

func (*EncDecSerializer) Value

func (es *EncDecSerializer) Value(ctx context.Context, field *schema.Field, dst reflect.Value, fieldValue interface{}) (interface{}, error)

Value implements serializer interface

Jump to

Keyboard shortcuts

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