database

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2021 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsErrNoRows

func IsErrNoRows(err error) bool

IsErrNoRows checks if an error is caused by an empty sql result set.

func IsErrUnique

func IsErrUnique(err error) bool

IsErrUnique checks if an error is caused by a unique constraint.

Types

type AddressDao

type AddressDao interface {
	// Insert inserts a new address.
	Insert(context.Context, Queryer, *models.AddressEntity) error
	// Delete deletes an existing address.
	Delete(context.Context, Queryer, *models.AddressEntity) error
	// FindAll returns all addresses including their domain name.
	FindAll(context.Context, Queryer) ([]AddressWithDomain, error)
	// FindByMailbox returns all addresses including their domain name by mailbox.
	FindByMailbox(context.Context, Queryer, *models.MailboxEntity) ([]AddressWithDomain, error)
}

AddressDao is a data access object for all address related queries.

func NewAddressDao

func NewAddressDao() AddressDao

NewAddressDao creates a new AddressDao.

type AddressWithDomain

type AddressWithDomain struct {
	models.AddressEntity
	DomainName string `db:"domain_name"`
}

AddressWithDomain is a helper type to eagerly fetch the domain name of an address.

type Conn

type Conn interface {
	Queryer
	Begin(context.Context) (Tx, error)
	Close() error
}

Conn is a connection to the sql database.

func OpenConnection

func OpenConnection() (Conn, error)

OpenConnection opens an sqlite3 database connection using the configuration from viper.

type DomainDao

type DomainDao interface {
	// Insert inserts a new domain.
	Insert(context.Context, Queryer, *models.DomainEntity) error
	// Update updates an existing domain.
	Update(context.Context, Queryer, *models.DomainEntity) error
	// Delete deletes an existing domain.
	Delete(context.Context, Queryer, *models.DomainEntity) error
	// FindAll returns all domains sorted by name.
	FindAll(context.Context, Queryer) ([]models.DomainEntity, error)
	// FindByName returns the domain matching the name.
	FindByName(context.Context, Queryer, string) (*models.DomainEntity, error)
}

DomainDao is a data access object for all domain related queries.

func NewDomainDao

func NewDomainDao() DomainDao

NewDomainDao creates a new DomainDao.

type MailDao

type MailDao interface {
	// Insert inserts a new mail.
	Insert(context.Context, Queryer, *models.MailEntity) error
	// Update updates an existing mail.
	Update(context.Context, Queryer, *models.MailEntity) error
	// FindByMailbox returns all mails that are not deleted and are "inboxed" to the mailbox.
	FindByMailbox(context.Context, Queryer, *models.MailboxEntity) ([]models.MailEntity, error)
	// FindDeletable returns all mails which are not yet deleted and are delivered or failed to all
	// recipients.
	FindDeletable(context.Context, Queryer) ([]models.MailEntity, error)
	// FindNextPending returns the next mail with at least one pending recipient.
	FindNextPending(context.Context, Queryer) (*models.MailEntity, error)
}

MailDao is a data access object for all mail related queries.

func NewMailDao

func NewMailDao() MailDao

NewMailDao creates a new MailDao.

type MailboxCredentialDao

type MailboxCredentialDao interface {
	// Upsert inserts new mailbox credentials. When there already is an entry for a mailbox, the
	// row will be updated instead.
	Upsert(context.Context, Queryer, *models.MailboxCredentialEntity) error
	// FindByMailbox returns the credentials associated with a mailbox.
	FindByMailbox(context.Context, Queryer, *models.MailboxEntity) (*models.MailboxCredentialEntity, error)
}

MailboxCredentialDao is a data access object for all mailbox-credential related queries.

func NewMailboxCredentialDao

func NewMailboxCredentialDao() MailboxCredentialDao

NewMailboxCredentialDao creates a new MailboxCredentialDao.

type MailboxDao

type MailboxDao interface {
	// Insert inserts a new mailbox.
	Insert(context.Context, Queryer, *models.MailboxEntity) error
	// Update updates an existing mailbox.
	Update(context.Context, Queryer, *models.MailboxEntity) error
	// DeleteMailbox deletes an existing mailbox.
	Delete(context.Context, Queryer, *models.MailboxEntity) error
	// FindAll returns all mailboxes.
	FindAll(context.Context, Queryer) ([]models.MailboxEntity, error)
	// FindByAddress returns the mailbox associated with an address.
	FindByAddress(context.Context, Queryer, models.Address) (*models.MailboxEntity, error)
}

MailboxDao is a data access object for all mailbox related queries.

func NewMailboxDao

func NewMailboxDao() MailboxDao

NewMailboxDao creates a new MailboxDao.

type Queryer

type Queryer interface {
	sqlx.ExtContext
}

Queryer is an interface for both transactions and the database connection itself.

type RecipientDao

type RecipientDao interface {
	// Insert inserts a new recipient.
	Insert(context.Context, Queryer, *models.RecipientEntity) error
	// Update updates an existing recipient.
	Update(context.Context, Queryer, *models.RecipientEntity) error
	// UpdateDelivered updates the status of all recipients matching the mail and mailbox to
	// StatusDelivered.
	UpdateDelivered(context.Context, Queryer, *models.MailboxEntity, *models.MailEntity) error
	// FindPending returns all pending recipients of a mail.
	FindPending(context.Context, Queryer, *models.MailEntity) ([]models.RecipientEntity, error)
}

RecipientDao is a data access object for all recipient related queries.

func NewRecipientDao

func NewRecipientDao() RecipientDao

NewRecipientDao creates a new RecipientDao.

type Tx

type Tx interface {
	Queryer
	Commit() error
	Rollback() error
	RollbackWith(func()) error
}

Tx is a database transaction, which can be rolled back or committed.

Jump to

Keyboard shortcuts

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