database

package
v0.0.0-...-9b6702c Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const RETRY_COUNT = 3

Variables

View Source
var Table = table{
	Chunk:            "chunk",
	ChunkKeyword:     "chunk_keyword",
	Keyword:          "keyword",
	MemoryKeyword:    "memory_keyword",
	Memory:           "memory",
	OriginalResource: "original_resource",
	Summary:          "summary",
}

Functions

func CommitMigration

func CommitMigration(cfg *common.Config, inMemorySource *InMemorySource, steps int) error

Types

type DB

type DB interface {
	Query(query string, args ...interface{}) (SQLRows, error)
	CurrentSchema() string
}

type InMemorySource

type InMemorySource struct {
	Migrations *source.Migrations
}

func Down

func Down(cfg *common.Config, sqlTemplates []common.SQLTemplate) *InMemorySource

func NewInMemorySource

func NewInMemorySource() *InMemorySource

func Up

func Up(cfg *common.Config, sqlTemplates []common.SQLTemplate) (*InMemorySource, int)

TODO: when ups (steps) exceeds total number of migrations (or total steps - last migration version), calculate the difference and apply

func (*InMemorySource) Close

func (s *InMemorySource) Close() error

func (*InMemorySource) First

func (s *InMemorySource) First() (uint, error)

func (*InMemorySource) Next

func (s *InMemorySource) Next(version uint) (uint, error)

func (*InMemorySource) Open

func (s *InMemorySource) Open(url string) (source.Driver, error)

func (*InMemorySource) Prev

func (s *InMemorySource) Prev(version uint) (uint, error)

func (*InMemorySource) ReadDown

func (s *InMemorySource) ReadDown(version uint) (io.ReadCloser, string, error)

func (*InMemorySource) ReadUp

func (s *InMemorySource) ReadUp(version uint) (io.ReadCloser, string, error)

type MindPalaceDB

type MindPalaceDB struct {
	ConnectionString string
	// contains filtered or unexported fields
}

func InitDB

func InitDB(cfg *common.Config) *MindPalaceDB

func (*MindPalaceDB) Close

func (m *MindPalaceDB) Close() error

func (*MindPalaceDB) ConstructSchema

func (m *MindPalaceDB) ConstructSchema(user string) string

func (*MindPalaceDB) CreateSchema

func (m *MindPalaceDB) CreateSchema(user string) (string, error)

func (*MindPalaceDB) CurrentSchema

func (m *MindPalaceDB) CurrentSchema() string

func (*MindPalaceDB) DB

func (m *MindPalaceDB) DB() *sql.DB

func (*MindPalaceDB) ListMPSchemas

func (m *MindPalaceDB) ListMPSchemas() ([]string, error)

func (*MindPalaceDB) Ping

func (m *MindPalaceDB) Ping(ctx context.Context) error

func (*MindPalaceDB) Query

func (m *MindPalaceDB) Query(query string, args ...any) (SQLRows, error)

func (*MindPalaceDB) SetSchema

func (m *MindPalaceDB) SetSchema(schema string)

type MockDB

type MockDB struct {
	mock.Mock
}

func (*MockDB) Close

func (m *MockDB) Close() error

func (*MockDB) CurrentSchema

func (m *MockDB) CurrentSchema() string

func (*MockDB) Query

func (m *MockDB) Query(query string, args ...interface{}) (SQLRows, error)

func (*MockDB) SetSchema

func (m *MockDB) SetSchema(schema string)

type MockRows

type MockRows struct {
	mock.Mock

	Values [][]interface{}
	// contains filtered or unexported fields
}

Mocking the database rows

func (*MockRows) Close

func (rows *MockRows) Close() error

func (*MockRows) ColumnTypes

func (rows *MockRows) ColumnTypes() ([]*sql.ColumnType, error)

func (*MockRows) Columns

func (rows *MockRows) Columns() ([]string, error)

func (*MockRows) Err

func (rows *MockRows) Err() error

func (*MockRows) Next

func (rows *MockRows) Next() bool

func (*MockRows) NextResultSet

func (rows *MockRows) NextResultSet() bool

func (*MockRows) Scan

func (rows *MockRows) Scan(dest ...interface{}) error

type MultiInstruction

type MultiInstruction struct {
	ID uuid.UUID
	// contains filtered or unexported fields
}

func NewMultiInstruction

func NewMultiInstruction(db *MindPalaceDB) *MultiInstruction

func (*MultiInstruction) Begin

func (t *MultiInstruction) Begin() error

func (*MultiInstruction) BeginTx

func (t *MultiInstruction) BeginTx(ctx context.Context) error

func (*MultiInstruction) Commit

func (t *MultiInstruction) Commit(ctx context.Context) error

func (*MultiInstruction) CurrentSchema

func (t *MultiInstruction) CurrentSchema() string

func (*MultiInstruction) Exec

func (t *MultiInstruction) Exec(ctx context.Context, query string, args ...interface{}) error

func (*MultiInstruction) Prepare

func (t *MultiInstruction) Prepare(ctx context.Context, query string) (*sql.Stmt, error)

func (*MultiInstruction) Query

func (t *MultiInstruction) Query(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

func (*MultiInstruction) QueryRow

func (t *MultiInstruction) QueryRow(ctx context.Context, query string, args ...interface{}) *sql.Row

func (*MultiInstruction) Rollback

func (t *MultiInstruction) Rollback(ctx context.Context) error

type SQLRows

type SQLRows interface {
	Close() error
	ColumnTypes() ([]*sql.ColumnType, error)
	Columns() ([]string, error)
	Err() error
	NextResultSet() bool
	Next() bool
	Scan(dest ...any) error
}

Jump to

Keyboard shortcuts

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