db

package
v0.0.0-...-033fc02 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InvalidColErr

func InvalidColErr(colName, tblName string) error

func InvalidTblErr

func InvalidTblErr(name string) error

func InvalidTypeErr

func InvalidTypeErr(column, typeName string) error

func WithDb

func WithDb(handler DbHandler) http.HandlerFunc

for endpoints that can use either the primary or an external database

func WithPrimary

func WithPrimary(handler DbHandler) http.HandlerFunc

for endpoints that only work with the primary database

Types

type Column

type Column struct {
	Type       string `json:"type"`
	Default    any    `json:"default"`
	PrimaryKey bool   `json:"primaryKey"`
	Unique     bool   `json:"unique"`
	NotNull    bool   `json:"notNull"`
	References string `json:"references"`
	OnDelete   string `json:"onDelete"`
	OnUpdate   string `json:"onUpdate"`
}

type Database

type Database struct {
	Client *sql.DB
	Schema SchemaCache
	// contains filtered or unexported fields
}

func ConnPrimary

func ConnPrimary() (Database, error)

func (Database) AlterTable

func (dao Database) AlterTable(table string, body io.ReadCloser) error

func (Database) CreateDb

func (dao Database) CreateDb(body io.ReadCloser) error

for use with the primary database

func (Database) CreateTable

func (dao Database) CreateTable(table string, body io.ReadCloser) error

func (Database) DeleteDb

func (dao Database) DeleteDb(name string) error

for use with the primary database

func (Database) DeleteRows

func (dao Database) DeleteRows(table string, params url.Values) ([]byte, error)

func (Database) DropTable

func (dao Database) DropTable(table string) error

func (Database) EditSchema

func (dao Database) EditSchema(body io.ReadCloser) error

func (Database) InsertRows

func (dao Database) InsertRows(table string, params url.Values, body io.ReadCloser, upsert bool) ([]byte, error)

func (*Database) InvalidateSchema

func (dao *Database) InvalidateSchema() error

func (Database) ListDbs

func (dao Database) ListDbs() ([]byte, error)

func (Database) QueryDbInfo

func (dao Database) QueryDbInfo(dbName string) (int32, string, SchemaCache, error)

func (Database) QueryJSON

func (dao Database) QueryJSON(query string, args ...any) ([]byte, error)

func (Database) QueryMap

func (dao Database) QueryMap(query string, args ...any) ([]interface{}, error)

func (Database) RegisterDb

func (dao Database) RegisterDb(body io.ReadCloser, dbToken string) error

creates a schema cache and stores it for an already existing turso db

func (Database) SelectRows

func (dao Database) SelectRows(table string, params url.Values) ([]byte, error)

func (Database) UpdateRows

func (dao Database) UpdateRows(table string, params url.Values, body io.ReadCloser) ([]byte, error)

type DbHandler

type DbHandler func(db Database, req *http.Request) ([]byte, error)

type Fk

type Fk struct {
	Table      string
	References string
	From       string
	To         string
}

type NewColumn

type NewColumn struct {
	Type       string `json:"type"`
	Default    any    `json:"default"`
	NotNull    bool   `json:"notNull"`
	References string `json:"references"`
	OnDelete   string `json:"onDelete"`
	OnUpdate   string `json:"onUpdate"`
}

type Param

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

type PkMap

type PkMap map[string]string

type Response

type Response struct {
	Data  []byte      `json:"data"`
	Error interface{} `json:"error"`
}

type SchemaCache

type SchemaCache struct {
	Tables TblMap
	Pks    PkMap
	Fks    []Fk
}

func QueryPrimaryInfo

func QueryPrimaryInfo(db *sql.DB) (SchemaCache, error)

type Table

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

type TblMap

type TblMap map[string]map[string]string

Jump to

Keyboard shortcuts

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