database

package
v0.0.0-...-0794c0a Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Migrations = map[int][]string{
	1: {
		`
		CREATE TABLE IF NOT EXISTS migration (
    		id INTEGER PRIMARY KEY NOT NULL,
    		updated_at timestamp DEFAULT CURRENT_TIMESTAMP,
    		migration_id INT NOT NULL UNIQUE
		)
		`,
		`
		INSERT INTO migration (migration_id) values(1)
		`,
	},
	2: {
		`
		CREATE TABLE IF NOT EXISTS item_count (
		    id INTEGER PRIMARY KEY NOT NULL,
		    owner VARCHAR(64) NOT NULL,
		    item_id VARCHAR(64) NOT NULL COLLATE NOCASE,
		    item_count INTEGER NOT NULL DEFAULT 0,
		    FOREIGN KEY(item_id) REFERENCES item(id),
		    UNIQUE(owner, item_id)
		)
		`,
		`
		CREATE TABLE IF NOT EXISTS item (
		    id VARCHAR(64) PRIMARY KEY NOT NULL,
		    name VARCHAR(255) UNIQUE COLLATE NOCASE
		)
		`,
		`
		INSERT INTO migration (migration_id) values(2)
		`,
	},
}

Functions

func NewDB

func NewDB(path string) (*sql.DB, error)

Types

type Gringotts

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

func NewGringotts

func NewGringotts(db *sql.DB) *Gringotts

func (*Gringotts) FindItem

func (g *Gringotts) FindItem(ctx context.Context, searchString string) ([]*Item, error)

func (*Gringotts) GetItemCount

func (g *Gringotts) GetItemCount(ctx context.Context, owner string, itemID int) (int, error)

func (*Gringotts) GetItemName

func (g *Gringotts) GetItemName(ctx context.Context, id string) (string, error)

func (*Gringotts) UpdateItemCounts

func (g *Gringotts) UpdateItemCounts(ctx context.Context, owner string, itemCounts map[string]int) error

func (*Gringotts) UpdateItems

func (g *Gringotts) UpdateItems(ctx context.Context, items map[string]string) error

type Item

type Item struct {
	ID    string
	Name  string
	Count int
}

type Migrator

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

func NewMigrator

func NewMigrator(db *sql.DB) *Migrator

func (*Migrator) GetLatestMigrationID

func (m *Migrator) GetLatestMigrationID() (int, error)

func (*Migrator) Migrate

func (m *Migrator) Migrate() error

Jump to

Keyboard shortcuts

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