api

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2021 License: LGPL-2.1 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreatePostgresDbInstance

func CreatePostgresDbInstance(host string, port int, user string, password string, dbname string) (*sql.DB, error)

func CreateSqliteDbInstance

func CreateSqliteDbInstance(name string) *sql.DB

func GetSqliteDriverVersion

func GetSqliteDriverVersion() (string, int, string)

Types

type AdvancedApi

type AdvancedApi struct {
	core.DbApi
	Cols        map[string]string
	FuncOnError func(err error)
	IsImportant bool
}

AdvancedApi just has more automation Cols is a map with all columns example:

map[string]string{
	"id": "INTEGER PRIMARY KEY AUTOINCREMENT",
	"name": "TEXT"
}

WARNING: do not put ',' or ')' no need in it FuncOnError is a custom function that will be called on error if isImportant is true

func NewAdvancedApi

func NewAdvancedApi(db *sql.DB, tableName string, cols map[string]string, customErrorFunction func(err error), isImportant bool) AdvancedApi

func (*AdvancedApi) DeleteAllBy

func (api *AdvancedApi) DeleteAllBy(cond string) error

func (*AdvancedApi) DeleteById

func (api *AdvancedApi) DeleteById(id int) error

func (*AdvancedApi) DropTable

func (api *AdvancedApi) DropTable() error

func (*AdvancedApi) GetComponentVersion

func (api *AdvancedApi) GetComponentVersion() string

func (*AdvancedApi) InsertWithId

func (api *AdvancedApi) InsertWithId(values []string) error

func (*AdvancedApi) SelectAll

func (api *AdvancedApi) SelectAll() (*sql.Rows, error)

func (*AdvancedApi) SelectById

func (api *AdvancedApi) SelectById(id int) *sql.Row

func (*AdvancedApi) Sync

func (api *AdvancedApi) Sync() error

func (*AdvancedApi) UpdateById

func (api *AdvancedApi) UpdateById(id int, updates string) error

type Api

type Api struct {
	core.DbApi
}

Api structure is a structure that will interact with sqlite

func CreateApi

func CreateApi(db *sql.DB, tableName string) Api

func (*Api) DeleteAllBy

func (api *Api) DeleteAllBy(cond string) error

it will delete all rows in db with specified condition

example: name="muka" AND id=1

func (*Api) DeleteById

func (api *Api) DeleteById(id int) error

func (*Api) DropTable

func (api *Api) DropTable() error

if you need to drop table just use it

func (*Api) GetComponentVersion

func (api *Api) GetComponentVersion() string

func (*Api) Insert

func (api *Api) Insert(cols string, values string) error

argument 'cols' is a string where you put all columns in which values will be inserted example: name, email argument 'values' is a string with values that will be inserted example: "muka", "cringer@asd.dq"

func (*Api) SelectAll

func (api *Api) SelectAll() *sql.Rows

if you need to get all rows just use it WARNING: it's returns *sql.Rows that means that other work you need to do on your own

func (*Api) SelectById

func (api *Api) SelectById(id int) *sql.Row

it will select item by id

func (*Api) Sync

func (api *Api) Sync(cols string) error

sync means "create table if not exists" argument 'cols' is just columns with all attributes example: "id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT"

func (*Api) UpdateById

func (api *Api) UpdateById(id int, updates string) error

this function will update a row with id that you will provide updates argument is a string with all cols need to be updated example: name = "muka", email = "cri@avd.fs"

Jump to

Keyboard shortcuts

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