sqlmodel

package
v0.0.0-...-bf83fb3 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DataTableName = "skyrin_dps_data"
	DataColumns   = `dps_pub_id, dps_data_type, dps_data_id, 
		dps_data_deleted, dps_data_version, dps_data_json,
		created_on, updated_on`
	DataUpsertOnConflict = `ON CONFLICT (dps_pub_id, dps_data_type, dps_data_id) 
		DO UPDATE
		SET
		dps_data_deleted=EXCLUDED.dps_data_deleted,
		dps_data_version=` + DataTableName + `.dps_data_version+1,
		dps_data_json=COALESCE(EXCLUDED.dps_data_json,` + DataTableName + `.dps_data_json),
		updated_on=now()`
	DataUpsertOnConflictReturning = DataUpsertOnConflict + " RETURNING dps_data_version"

	ECode070801 = e.Code0708 + "01"
	ECode070802 = e.Code0708 + "02"
	ECode070803 = e.Code0708 + "03"
	ECode070804 = e.Code0708 + "04"
	ECode070805 = e.Code0708 + "05"
	ECode070806 = e.Code0708 + "06"
	ECode070807 = e.Code0708 + "07"
	ECode070808 = e.Code0708 + "08"
	ECode070809 = e.Code0708 + "09"
	ECode07080A = e.Code0708 + "0A"
	ECode07080B = e.Code0708 + "0B"
	ECode07080C = e.Code0708 + "0C"
	ECode07080D = e.Code0708 + "0D"
)
View Source
const (
	PubTableName          = "skyrin_dps_pub"
	PubTableNameWithAlias = PubTableName + " AS p"
	PubColumns            = `dps_pub_id, dps_pub_code, dps_pub_name, dps_pub_status, created_on, updated_on`
	PubColumnsWithAlias   = `p.dps_pub_id, p.dps_pub_code, p.dps_pub_name, p.dps_pub_status, p.created_on, p.updated_on`

	ECode070601 = e.Code0706 + "01"
	ECode070602 = e.Code0706 + "02"
	ECode070603 = e.Code0706 + "03"
	ECode070604 = e.Code0706 + "04"
	ECode070605 = e.Code0706 + "05"
	ECode070606 = e.Code0706 + "06"
	ECode070607 = e.Code0706 + "07"
	ECode070608 = e.Code0706 + "08"
	ECode070609 = e.Code0706 + "09"
	ECode07060A = e.Code0706 + "0A"
	ECode07060B = e.Code0706 + "0B"
)
View Source
const (
	PubSubMapTableName = "skyrin_dps_pub_sub_map"
	PubSubMapColumns   = `dps_pub_id, dps_sub_id`
)
View Source
const (
	SubTableName = "skyrin_dps_sub"
	SubColumns   = `dps_sub_id, dps_sub_code, dps_sub_name, dps_sub_status, dps_sub_retries, created_on, updated_on`

	ECode070701 = e.Code0707 + "01"
	ECode070702 = e.Code0707 + "02"
	ECode070703 = e.Code0707 + "03"
	ECode070704 = e.Code0707 + "04"
	ECode070705 = e.Code0707 + "05"
	ECode070706 = e.Code0707 + "06"
	ECode070707 = e.Code0707 + "07"
	ECode070708 = e.Code0707 + "08"
	ECode070709 = e.Code0707 + "09"
	ECode07070A = e.Code0707 + "0A"
	ECode07070B = e.Code0707 + "0B"
)
View Source
const (
	SubDataTableName = "skyrin_dps_sub_data"
	SubDataColumns   = `` /* 230-byte string literal not displayed */

	SubDataColumnsWithID    = `dps_sub_data_id,` + SubDataColumns
	SubDataUpsertOnConflict = `ON CONFLICT (dps_sub_id, dps_pub_id, dps_data_type, dps_data_id)
		DO UPDATE
		SET
		dps_sub_data_deleted=EXCLUDED.dps_sub_data_deleted,
		dps_sub_data_version=EXCLUDED.dps_sub_data_version,
		dps_sub_data_status=EXCLUDED.dps_sub_data_status,
		dps_sub_data_hash=CASE
			WHEN EXCLUDED.dps_sub_data_hash <> '' THEN EXCLUDED.dps_sub_data_hash
			ELSE ` + SubDataTableName + `.dps_sub_data_hash
		END,
		dps_sub_data_json=COALESCE(EXCLUDED.dps_sub_data_json,` + SubDataTableName + `.dps_sub_data_json),
		dps_sub_data_retries=COALESCE(EXCLUDED.dps_sub_data_retries,` + SubDataTableName + `.dps_sub_data_retries),
		dps_sub_data_message=EXCLUDED.dps_sub_data_message,
		updated_on=NOW()
		WHERE ` + SubDataTableName + `.dps_sub_data_version<EXCLUDED.dps_sub_data_version
			OR (` +
		SubDataTableName + `.dps_sub_data_version=EXCLUDED.dps_sub_data_version AND ` +
		SubDataTableName + `.dps_sub_data_status='pending')`

	// Error constants
	ECode070901 = e.Code0709 + "01"
	ECode070902 = e.Code0709 + "02"
	ECode070903 = e.Code0709 + "03"
	ECode070904 = e.Code0709 + "04"
	ECode070905 = e.Code0709 + "05"
	ECode070906 = e.Code0709 + "06"
	ECode070907 = e.Code0709 + "07"
	ECode070908 = e.Code0709 + "08"
	ECode070909 = e.Code0709 + "09"
	ECode07090A = e.Code0709 + "0A"
	ECode07090B = e.Code0709 + "0B"
	ECode07090C = e.Code0709 + "0C"
	ECode07090D = e.Code0709 + "0D"
	ECode07090E = e.Code0709 + "0E"
)
View Source
const (
	// Error constants
	ECode070501 = e.Code0705 + "01"
	ECode070502 = e.Code0705 + "02"
)

Variables

This section is empty.

Functions

func DataGet

func DataGet(db *sql.Connection,
	p *DataGetParam) (sList []*model.Data, count int, err error)

DataGet performs select

func DataGetByPubIDDataTypeAndDataID

func DataGetByPubIDDataTypeAndDataID(db *sql.Connection,
	pubID int, dataType, dataID string) (d *model.Data, err error)

DataGetByPubIDDataTypeAndDataID fetch the specific record

func DataUpsert

func DataUpsert(db *sql.Connection, input *model.Data) (version int, err error)

DataUpsert inserts a record, returning the version

func PubGet

func PubGet(db *sql.Connection,
	p *PubGetParam) (sList []*model.Pub, count int, err error)

PubGet performs select

func PubGetByCode

func PubGetByCode(db *sql.Connection, code string) (p *model.Pub, err error)

PubGetByCode get by code

func PubGetBySubID

func PubGetBySubID(db *sql.Connection, subID int, f func(*model.Pub) error) (pList []*model.Pub, err error)

PubGetBySubID get by sub id

func PubInsert

func PubInsert(db *sql.Connection, input *model.Pub) (id int, err error)

PubInsert inserts a record

func PubSetStatus

func PubSetStatus(db *sql.Connection, id int, status string) (err error)

PubSetStatus updates the status

func SubDataCreateMissing

func SubDataCreateMissing(db *sql.Connection, subID int) (err error)

SubDataCreateMissing creates records from the data table that are missing in the sub data table

func SubDataGet

func SubDataGet(db *sql.Connection,
	p *SubDataGetParam) (sList []*model.SubData, count int, err error)

SubDataGet performs select

func SubDataGetBySubIDPubIDDataTypeAndDataIDForUpdate

func SubDataGetBySubIDPubIDDataTypeAndDataIDForUpdate(db *sql.Connection,
	subID, pubID int, dataType, dataID string, version int) (sd *model.SubData, err error)

SubDataGetBySubIDPubIDDataTypeAndDataIDForUpdate retrieves and locks the record for writing. If the version in the database is greater, then it does nothing

func SubDataGetProcessable

func SubDataGetProcessable(db *sql.Connection, minID, subID, limit int, f func(sd *model.SubData) error) (err error)

SubDataGetProcessable

func SubDataNewBulkUpsert

func SubDataNewBulkUpsert(db *sql.Connection) (bi *sql.BulkInsert)

SubDataNewBulkUpsert initializes and returns a new bulk inserter that will update on conflict

func SubDataUpdateFromPub

func SubDataUpdateFromPub(db *sql.Connection, subID int) (err error)

SubDataUpdateFromPub udpates the sub data record with the data record. If the data record has a higher version, it sets that and marks the sub data record as pending

func SubDataUpsert

func SubDataUpsert(db *sql.Connection, sd *model.SubData) (err error)

SubDataUpsert inserts a record

func SubGet

func SubGet(db *sql.Connection,
	p *SubGetParam) (sList []*model.Sub, count int, err error)

SubGet performs select

func SubGetByCode

func SubGetByCode(db *sql.Connection, code string) (s *model.Sub, err error)

SubGetByCode get by code

func SubInsert

func SubInsert(db *sql.Connection, input *model.Sub) (id int, err error)

SubInsert inserts a record

func SubSetRetries

func SubSetRetries(db *sql.Connection, id, retries int) (err error)

SubSetRetries set the retries

func SubSetStatus

func SubSetStatus(db *sql.Connection, id int, status string) (err error)

SubSetStatus updates the status

Types

type DataBulkInsert

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

DataBulkInsert optimized way to upsert records

func NewDataBulkInsert

func NewDataBulkInsert(db *sql.Connection) (sdbc *DataBulkInsert)

NewDataBulkInsert initializes and returns a new bulk insert for creating/updating pub data records. If updating, it will increment the version and update the deleted/json values Note: whatever calls this must call Flush and Close when done

func (*DataBulkInsert) Add

func (b *DataBulkInsert) Add(d *model.Data) (rowsAdded int, err error)

Add adds the item to the bulk insert. If it saves to the database, it will return the number of rows added

func (*DataBulkInsert) Close

func (b *DataBulkInsert) Close() (errList []error)

Close closes all open statements

func (*DataBulkInsert) Flush

func (b *DataBulkInsert) Flush() (err error)

Flush saves any pending records

func (*DataBulkInsert) GetCount

func (b *DataBulkInsert) GetCount() (count int)

GetCount returns the number of rows added since the last flush call

func (*DataBulkInsert) GetMaxRowPerInsert

func (b *DataBulkInsert) GetMaxRowPerInsert() (maxRowPerInsert uint)

GetMaxRowPerInsert gets the currently set maximum rows to insert at a time.

func (*DataBulkInsert) GetTotal

func (b *DataBulkInsert) GetTotal() (count int)

GetTotal returns the total number of rows added

func (*DataBulkInsert) SetMaxRowPerInsert

func (b *DataBulkInsert) SetMaxRowPerInsert(maxRows uint) (actualMaxRows uint)

SetMaxRowPerInsert sets the maximum rows to insert at a time. If the specified number of rows makes the parameters per insert exceed the absolute max, then the max rows will be decremented until it falls into an allowed range

func (*DataBulkInsert) SetPostInsert

func (b *DataBulkInsert) SetPostInsert(f func(rowCount int) error)

SetPostInsert assigns a post insert func to call, or unassigns if nil

func (*DataBulkInsert) SetPreInsert

func (b *DataBulkInsert) SetPreInsert(f func() error)

SetPreInsert assigns a pre insert func to call, or unassigns if nil

type DataGetParam

type DataGetParam struct {
	Limit         *uint64
	Offset        *uint64
	NoLimit       bool
	PubID         *int
	Type          *string
	ID            *string
	Search        *string
	FlagCount     bool
	FlagForUpdate bool
	OrderByID     string
	DataHandler   func(*model.Data) error
}

DataGetParam model

type PubGetParam

type PubGetParam struct {
	Limit         *uint64
	Offset        *uint64
	NoLimit       bool
	ID            *int
	Code          *string
	Status        *string
	StatusList    *[]string
	SubID         *int
	Search        *string
	FlagCount     bool
	FlagForUpdate bool
	OrderByID     string
	DataHandler   func(*model.Pub) error
}

PubGetParam model

type SubDataBulk

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

SubDataBulk optimized way to mark records as completed

func NewSubDataBulk

func NewSubDataBulk(db *sql.Connection) (sdbc *SubDataBulk)

NewSubDataBulk initializes and returns a new bulk updater for marking sub data as complete. It sets the status to complete, the hash and the json bytes if present Note: whatever calls this must call Flush and Close when done

func (*SubDataBulk) Add

func (b *SubDataBulk) Add(sd *model.SubData) (rowsUpdated int, err error)

Add adds the item to the bulk insert. If it saves to the database, it will return the number of rows added

func (*SubDataBulk) Close

func (b *SubDataBulk) Close() (errList []error)

Close closes all open statements

func (*SubDataBulk) Flush

func (b *SubDataBulk) Flush() (err error)

Flush saves any pending records

func (*SubDataBulk) GetCount

func (b *SubDataBulk) GetCount() (count int)

GetCount returns the number of rows added since the last flush call

func (*SubDataBulk) GetTotal

func (b *SubDataBulk) GetTotal() (count int)

GetTotal returns the total number of rows added

type SubDataGetParam

type SubDataGetParam struct {
	Limit          *uint64
	Offset         *uint64
	NoLimit        bool
	SubID          *int
	PubID          *int
	Type           *string
	ID             *string
	VersionLess    *int
	FlagCount      bool
	FlagForUpdate  bool
	OrderByID      string
	SubDataHandler func(*model.SubData) error
}

SubDataGetParam model

type SubGetParam

type SubGetParam struct {
	Limit         *uint64
	Offset        *uint64
	NoLimit       bool
	ID            *int
	Code          *string
	Status        *string
	StatusList    *[]string
	Search        *string
	FlagCount     bool
	FlagForUpdate bool
	OrderByID     string
	DataHandler   func(*model.Sub) error
}

SubGetParam model

Jump to

Keyboard shortcuts

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