store

package
v0.0.0-...-ca9fd5b Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package store is a generated GoMock package.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnknownDriver defines a named error for unknown store drivers.
	ErrUnknownDriver = errors.New("unknown database driver")
)
View Source
var (
	// Migrations define all database migrations.
	Migrations = []*gormigrate.Migration{
		{
			ID: "202206181600001",
			Migrate: func(tx *gorm.DB) error {
				type User struct {
					ID        string `gorm:"primaryKey;length:36"`
					Slug      string `gorm:"unique;length:255"`
					Username  string `gorm:"unique;length:255"`
					Password  string `gorm:"length:255"`
					Email     string `gorm:"unique;length:255"`
					Firstname string `gorm:"length:255"`
					Lastname  string `gorm:"length:255"`
					Active    bool   `gorm:"default:false"`
					Admin     bool   `gorm:"default:false"`
					CreatedAt time.Time
					UpdatedAt time.Time
				}

				return tx.Migrator().CreateTable(&User{})
			},
			Rollback: func(tx *gorm.DB) error {
				return tx.Migrator().DropTable("users")
			},
		},
		{
			ID: "202206181600002",
			Migrate: func(tx *gorm.DB) error {
				type Team struct {
					ID        string `gorm:"primaryKey;length:36"`
					Slug      string `gorm:"unique;length:255"`
					Name      string `gorm:"unique;length:255"`
					CreatedAt time.Time
					UpdatedAt time.Time
				}

				return tx.Migrator().CreateTable(&Team{})
			},
			Rollback: func(tx *gorm.DB) error {
				return tx.Migrator().DropTable("teams")
			},
		},
		{
			ID: "202206181600003",
			Migrate: func(tx *gorm.DB) error {
				type Member struct {
					TeamID    string `gorm:"index:idx_id,unique;length:36"`
					UserID    string `gorm:"index:idx_id,unique;length:36"`
					CreatedAt time.Time
					UpdatedAt time.Time
				}

				return tx.Migrator().CreateTable(&Member{})
			},
			Rollback: func(tx *gorm.DB) error {
				return tx.Migrator().DropTable("members")
			},
		},
		{
			ID: "202206181600004",
			Migrate: func(tx *gorm.DB) error {
				type Member struct {
					TeamID string `gorm:"index:idx_id,unique;length:36"`
					UserID string `gorm:"index:idx_id,unique;length:36"`
				}

				type Team struct {
					ID    string    `gorm:"primaryKey"`
					Users []*Member `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
				}

				return tx.Migrator().CreateConstraint(&Team{}, "Users")
			},
			Rollback: func(tx *gorm.DB) error {
				type Member struct {
					TeamID string `gorm:"index:idx_id,unique;length:36"`
					UserID string `gorm:"index:idx_id,unique;length:36"`
				}

				type Team struct {
					ID    string    `gorm:"primaryKey"`
					Users []*Member `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
				}

				return tx.Migrator().DropConstraint(&Team{}, "Users")
			},
		},
		{
			ID: "202206181600005",
			Migrate: func(tx *gorm.DB) error {
				type Member struct {
					TeamID string `gorm:"index:idx_id,unique;length:36"`
					UserID string `gorm:"index:idx_id,unique;length:36"`
				}

				type User struct {
					ID    string    `gorm:"primaryKey"`
					Teams []*Member `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
				}

				return tx.Migrator().CreateConstraint(&User{}, "Teams")
			},
			Rollback: func(tx *gorm.DB) error {
				type Member struct {
					TeamID string `gorm:"index:idx_id,unique;length:36"`
					UserID string `gorm:"index:idx_id,unique;length:36"`
				}

				type User struct {
					ID    string    `gorm:"primaryKey"`
					Teams []*Member `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
				}

				return tx.Migrator().DropConstraint(&User{}, "Teams")
			},
		},
	}
)

Functions

func Slugify

func Slugify(tx *gorm.DB, value, id string) string

Slugify generates a slug.

Types

type GormLogger

type GormLogger struct {
	SlowThreshold time.Duration
}

GormLogger defines a Gorm compatible logger.

func NewGormLogger

func NewGormLogger() *GormLogger

NewGormLogger prepares a Gorm compatible logger.

func (*GormLogger) Error

func (l *GormLogger) Error(_ context.Context, msg string, data ...interface{})

Error implements the logger.Interface.

func (*GormLogger) Info

func (l *GormLogger) Info(_ context.Context, msg string, data ...interface{})

Info implements the logger.Interface.

func (*GormLogger) LogMode

func (l *GormLogger) LogMode(_ logger.LogLevel) logger.Interface

LogMode implements the logger.Interface.

func (*GormLogger) Trace

func (l *GormLogger) Trace(_ context.Context, begin time.Time, fc func() (string, int64), err error)

Trace implements the logger.Interface.

func (*GormLogger) Warn

func (l *GormLogger) Warn(_ context.Context, msg string, data ...interface{})

Warn implements the logger.Interface.

type GormStore

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

GormStore implements the Store interface.

func (*GormStore) Admin

func (s *GormStore) Admin(username, password, email string) error

Admin creates an initial admin user within the database.

func (*GormStore) Close

func (s *GormStore) Close() error

Close simply closes the database connection.

func (*GormStore) Handle

func (s *GormStore) Handle() *gorm.DB

Handle returns a database handle.

func (*GormStore) Info

func (s *GormStore) Info() map[string]interface{}

Info returns some basic db informations.

func (*GormStore) Migrate

func (s *GormStore) Migrate() error

Migrate executes required db migrations.

func (*GormStore) Open

func (s *GormStore) Open() error

Open simply opens the database connection.

func (*GormStore) Ping

func (s *GormStore) Ping() error

Ping just tests the database connection.

func (*GormStore) Prepare

func (s *GormStore) Prepare() error

Prepare is preparing some database behavior.

type MockStore

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

MockStore is a mock of Store interface.

func NewMockStore

func NewMockStore(ctrl *gomock.Controller) *MockStore

NewMockStore creates a new mock instance.

func (*MockStore) Admin

func (m *MockStore) Admin(arg0, arg1, arg2 string) error

Admin mocks base method.

func (*MockStore) Close

func (m *MockStore) Close() error

Close mocks base method.

func (*MockStore) EXPECT

func (m *MockStore) EXPECT() *MockStoreMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockStore) Handle

func (m *MockStore) Handle() *gorm.DB

Handle mocks base method.

func (*MockStore) Info

func (m *MockStore) Info() map[string]interface{}

Info mocks base method.

func (*MockStore) Migrate

func (m *MockStore) Migrate() error

Migrate mocks base method.

func (*MockStore) Open

func (m *MockStore) Open() error

Open mocks base method.

func (*MockStore) Ping

func (m *MockStore) Ping() error

Ping mocks base method.

func (*MockStore) Prepare

func (m *MockStore) Prepare() error

Prepare mocks base method.

type MockStoreMockRecorder

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

MockStoreMockRecorder is the mock recorder for MockStore.

func (*MockStoreMockRecorder) Admin

func (mr *MockStoreMockRecorder) Admin(arg0, arg1, arg2 interface{}) *gomock.Call

Admin indicates an expected call of Admin.

func (*MockStoreMockRecorder) Close

func (mr *MockStoreMockRecorder) Close() *gomock.Call

Close indicates an expected call of Close.

func (*MockStoreMockRecorder) Handle

func (mr *MockStoreMockRecorder) Handle() *gomock.Call

Handle indicates an expected call of Handle.

func (*MockStoreMockRecorder) Info

func (mr *MockStoreMockRecorder) Info() *gomock.Call

Info indicates an expected call of Info.

func (*MockStoreMockRecorder) Migrate

func (mr *MockStoreMockRecorder) Migrate() *gomock.Call

Migrate indicates an expected call of Migrate.

func (*MockStoreMockRecorder) Open

func (mr *MockStoreMockRecorder) Open() *gomock.Call

Open indicates an expected call of Open.

func (*MockStoreMockRecorder) Ping

func (mr *MockStoreMockRecorder) Ping() *gomock.Call

Ping indicates an expected call of Ping.

func (*MockStoreMockRecorder) Prepare

func (mr *MockStoreMockRecorder) Prepare() *gomock.Call

Prepare indicates an expected call of Prepare.

type Store

type Store interface {
	Info() map[string]interface{}
	Prepare() error
	Open() error

	Close() error
	Ping() error
	Migrate() error
	Admin(string, string, string) error
	Handle() *gorm.DB
}

Store provides the interface for the store implementations.

func MustGormStore

func MustGormStore(cfg config.Database) Store

MustGormStore simply calls NewGormStore and panics on an error.

func NewGormStore

func NewGormStore(cfg config.Database) (Store, error)

NewGormStore initializes a new GORM

Jump to

Keyboard shortcuts

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