db

package
v0.0.0-...-d270eb1 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Database connection

Migration execution

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

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

type AppRepository

type AppRepository struct {
	Log *log.Logger
	// contains filtered or unexported fields
}

func InitAppRepo

func InitAppRepo(dbg bool) *AppRepository

func (AppRepository) CreateOrUpdate

func (a AppRepository) CreateOrUpdate(h string, t string) error

func (AppRepository) GetByHandle

func (a AppRepository) GetByHandle(h string) (*App, error)

Retrieve by handle

type DBConn

type DBConn struct {
	Log *log.Logger
	// contains filtered or unexported fields
}

func Connect

func Connect(dbg bool) *DBConn

Create/Connect to database

type Files

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

Migration slices

type Migration

type Migration struct {
	ID        int       `db:"id"`
	Name      string    `db:"name"`
	Applied   bool      `db:"applied"`
	CreatedAt time.Time `db:"created_at"`
}

Migration Record

func (Migration) GetPath

func (m Migration) GetPath(d string) string

Build file path for migration file

Uses dir from MigrationRunner

type MigrationRunner

type MigrationRunner struct {
	Dir   string
	Conn  *DBConn
	Files Files
	Log   *log.Logger
}

Execution Context for Migrations

Holds state and defines container for migration files

func Runner

func Runner(d string, c *DBConn, dbg bool) *MigrationRunner

MigrationRunner constructor

func (MigrationRunner) CheckApplied

func (r MigrationRunner) CheckApplied(f fs.FileInfo) (bool, bool)

Check migration record

If applied, ensure that the forward migrations aren't reverted

func (MigrationRunner) CheckExists

func (r MigrationRunner) CheckExists(f fs.FileInfo) (bool, error)

Checks for stored but unapplied migrations (TODO)

func (MigrationRunner) CheckMigrationsTable

func (r MigrationRunner) CheckMigrationsTable() error

Check for the existence of Migration Table

Create it if it doesn't.

func (MigrationRunner) CheckPending

func (r MigrationRunner) CheckPending(f fs.FileInfo) (bool, error)

Checks for stored but unapplied migrations (TODO)

func (MigrationRunner) Execute

func (r MigrationRunner) Execute() error

Runs migration process

func (MigrationRunner) FindAndApplyMigration

func (r MigrationRunner) FindAndApplyMigration(f fs.FileInfo) error

Apply a specific migration

Finds the row, runs the script, updates the row

func (MigrationRunner) GetMigration

func (r MigrationRunner) GetMigration(m *Migration, f fs.FileInfo) error

func (*MigrationRunner) GetMigrationFiles

func (r *MigrationRunner) GetMigrationFiles() error

Opens migrations directory and returns list of files

Defaults to lib/db/migrations/*.sql

func (MigrationRunner) InsertMigrations

func (r MigrationRunner) InsertMigrations() error

Creates Migration Records

Inserts Rows into Database

func (MigrationRunner) RevertMigration

func (r MigrationRunner) RevertMigration(f fs.FileInfo) error

Revert a specific migration (TODO)

Checks for the presence of a down migration file

func (MigrationRunner) RunMigrations

func (r MigrationRunner) RunMigrations() error

Runs migrations

func (MigrationRunner) SetApplied

func (r MigrationRunner) SetApplied(f fs.FileInfo) error

type Repository

type Repository interface{}

Jump to

Keyboard shortcuts

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