db

package
v0.0.0-...-1a4ec74 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close(ctx context.Context) error

Close is closing the database connection

func ConnectPostgres

func ConnectPostgres(c *PostgresConfig) (*sql.DB, error)

ConnectPostgres is connecting to a Postgres database

func Delete

func Delete(ctx context.Context, id int32) (int64, error)

Delete is deleting the data from the database

func Get

func Get(ctx context.Context, id int32) (*todolistpb.Todo, error)

Get is getting the data from the database

func Insert

func Insert(ctx context.Context, todo *todolistpb.Todo) (int32, error)

Insert is inserting the data to the database

func List

func List(ctx context.Context) ([]*todolistpb.Todo, error)

List is listing the data

func SetRepository

func SetRepository(ctx context.Context, repository Repository) context.Context

SetRepository sets the repository

func Setup

func Setup(c *PostgresConfig) *sql.DB

Setup the databse

func Update

func Update(ctx context.Context, todo *todolistpb.Todo) (*todolistpb.Todo, error)

Update is updating the data in the database

Types

type MockDB

type MockDB struct {
}

MockDB interface

func (*MockDB) Close

func (m *MockDB) Close() error

Close is closing the database connection

func (*MockDB) Delete

func (m *MockDB) Delete(id int32) (int64, error)

Delete is deleting the data from the database

func (*MockDB) Get

func (m *MockDB) Get(id int32) (*todolistpb.Todo, error)

Get is getting the data from the database

func (*MockDB) Insert

func (m *MockDB) Insert(todo *todolistpb.Todo) (int32, error)

Insert is inserting the data to the database

func (*MockDB) List

func (m *MockDB) List() ([]*todolistpb.Todo, error)

List is listing the data

func (*MockDB) Update

func (m *MockDB) Update(todo *todolistpb.Todo) (*todolistpb.Todo, error)

Update is updating the data in the database

type Postgres

type Postgres struct {
	DB *sql.DB
}

Postgres sql interface

func (*Postgres) Close

func (p *Postgres) Close() error

Close is closing the database connection

func (*Postgres) Delete

func (p *Postgres) Delete(id int32) (int64, error)

Delete is deleting the data from the database

func (*Postgres) Get

func (p *Postgres) Get(id int32) (*todolistpb.Todo, error)

Get is getting the data from the database

func (*Postgres) Insert

func (p *Postgres) Insert(todo *todolistpb.Todo) (int32, error)

Insert is inserting the data to the database

func (*Postgres) List

func (p *Postgres) List() ([]*todolistpb.Todo, error)

List is listing the data

func (*Postgres) Update

func (p *Postgres) Update(todo *todolistpb.Todo) (*todolistpb.Todo, error)

Update is updating the data in the database

type PostgresConfig

type PostgresConfig struct {
	User     string
	Password string
	Host     string
	Port     string
}

PostgresConfig holds the configs

type Repository

type Repository interface {
	Close() error
	Insert(*todolistpb.Todo) (int32, error)
	Get(int32) (*todolistpb.Todo, error)
	Update(*todolistpb.Todo) (*todolistpb.Todo, error)
	Delete(int32) (int64, error)
	List() ([]*todolistpb.Todo, error)
}

Repository interface

Jump to

Keyboard shortcuts

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