jsonb

package
v0.0.0-...-0b1d0d2 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

README

This package implements the interface dao.Crud for Postgres JSONB field.

This implementation have in mind multi tenant architecture where each tenant has its own table in the database, here are some key features of this implementation.

  • Each tenant has their table in database, having completely isolation the data between tenants
  • Tables are created automatically for each tenant if needed
  • All the objects are stored as doc field, this make this implementation schemaless, no worries about schema changes
  • All tenant space/table has a fixed structured and optimized

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database[T dao.ObjI[T]] struct {
	Option Options
	// contains filtered or unexported fields
}

func NewDataBase

func NewDataBase[T dao.ObjI[T]](dbConnection *gorm.DB, tableName string) *Database[T]

NewDataBase factory method to create instance of Database struct dbConnection is the database connection used for all operation tenantId is the table will be used to insert data

func (*Database[T]) CommitTransaction

func (d *Database[T]) CommitTransaction() (err error)

func (*Database[T]) Create

func (d *Database[T]) Create(ctx context.Context, obj T) (T, error)

func (*Database[T]) Delete

func (d *Database[T]) Delete(ctx context.Context, id string) error

func (*Database[T]) DeleteHard

func (d *Database[T]) DeleteHard(ctx context.Context, id string) error

func (*Database[T]) Get

func (d *Database[T]) Get(ctx context.Context, id string) (t T, err error)

func (*Database[T]) List

func (d *Database[T]) List(ctx context.Context, f filter.Filter) (records []T, err error)

func (*Database[T]) RollbackTransaction

func (d *Database[T]) RollbackTransaction() (err error)

func (*Database[T]) Save

func (d *Database[T]) Save(ctx context.Context, insert bool, objs ...T) (list []T, err error)

Save objects whatever is insert or update, based on id the save method decide which operation is

func (*Database[T]) Select

func (d *Database[T]) Select(ctx context.Context, dest interface{}, query string, args ...interface{}) (err error)

func (*Database[T]) StartTransaction

func (d *Database[T]) StartTransaction() (err error)

func (*Database[T]) Update

func (d *Database[T]) Update(ctx context.Context, obj T, FieldNames dao.UpdateField) error

type Doc

type Doc struct {
	Id         string
	Collection string       `db:"collection"`
	DeletedAt  sql.NullTime `db:"deleted_at"`
	Doc        string
}

type MigrationModel

type MigrationModel struct {
	Id        int
	CreatedAt time.Time `Db:"created_at"`
	Module    string    `Db:"module"`
	Name      string    `Db:"name"`
	SQL       string
}

MigrationModel mode used to manage migrationsSingleton

func NewMigration

func NewMigration(dbName string) *MigrationModel

NewDbMigration factory method to create a new instance of MigrationModel

func (*MigrationModel) GetMigrationNumber

func (m *MigrationModel) GetMigrationNumber() int64

GetMigrationNumber get the current migration number

func (*MigrationModel) TableName

func (m *MigrationModel) TableName() string

TableName is used by the Gorm to define table name

type Options

type Options struct {
	// FieldSnakeCase set true to convert the fields to snake case before marhsal process
	FieldSnakeCase bool
}

type ViolationUniqKey

type ViolationUniqKey struct {
	FieldName string
	Value     string
	// contains filtered or unexported fields
}

func (ViolationUniqKey) Error

func (v ViolationUniqKey) Error() string

Jump to

Keyboard shortcuts

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