database

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 2, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package database provides a wrapper around the gorm package providing convenience functions around database management, model creation, etc... it currently supports PostreSQL and Sqlite but you can easily add support for your own databases by registering the drivers

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

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

func New

func New(opts *Opts) (*Database, error)

New returns a new database client

func (*Database) AutoMigrate

func (d *Database) AutoMigrate() error

AutoMigrate is used to automatically migrate datbase tables

func (*Database) Close

func (d *Database) Close() error

Close shuts down the database

func (*Database) DB

func (d *Database) DB() *gorm.DB

DB returns the underlying gorm database

func (*Database) Migrator

func (d *Database) Migrator() gorm.Migrator

Migrator returns the underlying database migrator, useful for managing the database

type Date

type Date time.Time

Date provides a time.Time wrapper for databases which may not support time formats

func (Date) GormDataType

func (date Date) GormDataType() string

GormDataType gorm common data type

func (*Date) Scan

func (date *Date) Scan(value interface{}) (err error)

func (Date) Value

func (date Date) Value() (driver.Value, error)

type Opts

type Opts struct {
	Type           string
	Host           string
	Port           string
	User           string
	Password       string
	DBName         string
	DBPath         string
	SSLModeDisable bool
}

Opts is used to configure database connections

func OptsFromConfig

func OptsFromConfig(cfg config.Database) *Opts

OptsFromConfig returns database options from a config file

func (*Opts) DSN

func (db *Opts) DSN() string

DSN returns the config string used with gorm

func (*Opts) Open

func (db *Opts) Open() (gorm.Dialector, error)

Open returns the gorm dialector for the corresponding db type

Jump to

Keyboard shortcuts

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