db

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

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

Go to latest
Published: Jun 29, 2015 License: GPL-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Setup

func Setup(opts r.ConnectOpts) error

Setup configures the RethinkDB server

Types

type AccountsTable

type AccountsTable struct {
	RethinkCRUD

	Tokens *TokensTable
}

AccountsTable implements the CRUD interface for accounts

func (*AccountsTable) FindAccountByName

func (users *AccountsTable) FindAccountByName(name string) (*models.Account, error)

FindAccountByName returns an account with specified name

func (*AccountsTable) GetAccount

func (users *AccountsTable) GetAccount(id string) (*models.Account, error)

GetAccount returns an account with specified ID

func (*AccountsTable) GetTokenOwner

func (a *AccountsTable) GetTokenOwner(token *models.Token) (*models.Account, error)

func (*AccountsTable) IsEmailUsed

func (a *AccountsTable) IsEmailUsed(email string) (bool, error)

func (*AccountsTable) IsUsernameUsed

func (a *AccountsTable) IsUsernameUsed(name string) (bool, error)

type AddressesTable

type AddressesTable struct {
	RethinkCRUD
}

func (*AddressesTable) DeleteOwnedBy

func (a *AddressesTable) DeleteOwnedBy(id string) error

func (*AddressesTable) GetAddress

func (a *AddressesTable) GetAddress(id string) (*models.Address, error)

func (*AddressesTable) GetOwnedBy

func (a *AddressesTable) GetOwnedBy(id string) ([]*models.Address, error)

type ContactsTable

type ContactsTable struct {
	RethinkCRUD
}

Contacts implements the CRUD interface for tokens

func (*ContactsTable) DeleteOwnedBy

func (c *ContactsTable) DeleteOwnedBy(id string) error

DeleteOwnedBy deletes all contacts owned by id

func (*ContactsTable) GetContact

func (c *ContactsTable) GetContact(id string) (*models.Contact, error)

GetContact returns a token with specified name

func (*ContactsTable) GetOwnedBy

func (c *ContactsTable) GetOwnedBy(id string) ([]*models.Contact, error)

GetOwnedBy returns all contacts owned by id

type DatabaseError

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

DatabaseError is the wrapper for RethinkDB errors that allows passing more data with the message

func NewDatabaseError

func NewDatabaseError(t RethinkTable, err error, message string) *DatabaseError

NewDatabaseError creates a new DatabaseError, wraps err and adds a message

func (*DatabaseError) Error

func (d *DatabaseError) Error() string

type Default

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

Default contains the basic implementation of the gorethinkCRUD interface

func NewCRUDTable

func NewCRUDTable(session *gorethink.Session, db, table string) *Default

NewCRUDTable sets up a new Default struct

func (*Default) Delete

func (d *Default) Delete(pred interface{}) error

Delete deletes resources that match the passed filter

func (*Default) DeleteID

func (d *Default) DeleteID(id string) error

DeleteID deletes a resource with specified ID

func (*Default) Find

func (d *Default) Find(id string) (*gorethink.Cursor, error)

Find searches for a resource in the database and then returns a cursor

func (*Default) FindBy

func (d *Default) FindBy(key string, value interface{}) (*gorethink.Cursor, error)

FindBy is an utility for fetching values if they are stored in a key-value manenr.

func (*Default) FindByAndCount

func (d *Default) FindByAndCount(key string, value interface{}) (int, error)

func (*Default) FindByAndFetch

func (d *Default) FindByAndFetch(key string, value interface{}, results interface{}) error

FindByAndFetch retrieves a value by key and then fills results with the result.

func (*Default) FindByAndFetchOne

func (d *Default) FindByAndFetchOne(key string, value interface{}, result interface{}) error

FindByAndFetchOne retrieves a value by key and then fills result with the first row of the result

func (*Default) FindByIndex

func (d *Default) FindByIndex(index string, values ...interface{}) (*gorethink.Cursor, error)

FindByIndex filters all resources whose index is matching

func (*Default) FindByIndexFetch

func (d *Default) FindByIndexFetch(results interface{}, index string, values ...interface{}) error

FindByIndexFetch filters all resources whose index is matching and fills results with all found resources

func (*Default) FindByIndexFetchOne

func (d *Default) FindByIndexFetchOne(result interface{}, index string, values ...interface{}) error

FindByIndexFetchOne filters all resources whose index is matching and fills result with the first one found

func (*Default) FindFetchOne

func (d *Default) FindFetchOne(id string, value interface{}) error

FindFetchOne searches for a resource and then unmarshals the first row into value

func (*Default) GetDBName

func (d *Default) GetDBName() string

GetDBName returns database's name

func (*Default) GetSession

func (d *Default) GetSession() *gorethink.Session

GetSession returns the current session

func (*Default) GetTable

func (d *Default) GetTable() gorethink.Term

GetTable returns the table as a gorethink.Term

func (*Default) GetTableName

func (d *Default) GetTableName() string

GetTableName returns table's name

func (*Default) Insert

func (d *Default) Insert(data interface{}) error

Insert inserts a document into the database

func (*Default) Update

func (d *Default) Update(data interface{}) error

Update performs an update on an existing resource according to passed data

func (*Default) UpdateID

func (d *Default) UpdateID(id string, data interface{}) error

UpdateID performs an update on an existing resource with ID that equals the id argument

func (*Default) Where

func (d *Default) Where(filter map[string]interface{}) (*gorethink.Cursor, error)

Where allows filtering with multiple fields

func (*Default) WhereAndFetch

func (d *Default) WhereAndFetch(filter map[string]interface{}, results interface{}) error

WhereAndFetch filters with multiple fields and then fills results with all found resources

func (*Default) WhereAndFetchOne

func (d *Default) WhereAndFetchOne(filter map[string]interface{}, result interface{}) error

WhereAndFetchOne filters with multiple fields and then fills result with the first found resource

type EmailsTable

type EmailsTable struct {
	RethinkCRUD
}

Emails implements the CRUD interface for tokens

func (*EmailsTable) CountOwnedBy

func (e *EmailsTable) CountOwnedBy(id string) (int, error)

func (*EmailsTable) DeleteByThread

func (e *EmailsTable) DeleteByThread(id string) error

func (*EmailsTable) DeleteOwnedBy

func (e *EmailsTable) DeleteOwnedBy(id string) error

DeleteOwnedBy deletes all emails owned by id

func (*EmailsTable) GetByThread

func (e *EmailsTable) GetByThread(thread string) ([]*models.Email, error)

func (*EmailsTable) GetEmail

func (e *EmailsTable) GetEmail(id string) (*models.Email, error)

GetEmail returns a token with specified name

func (*EmailsTable) GetOwnedBy

func (e *EmailsTable) GetOwnedBy(id string) ([]*models.Email, error)

GetOwnedBy returns all emails owned by id

func (*EmailsTable) GetThreadManifest

func (e *EmailsTable) GetThreadManifest(thread string) (string, error)

func (*EmailsTable) List

func (e *EmailsTable) List(
	owner string,
	sort []string,
	offset int,
	limit int,
	thread string,
) ([]*models.Email, error)

type FilesTable

type FilesTable struct {
	RethinkCRUD
	Emails *EmailsTable
}

func (*FilesTable) CountByEmail

func (f *FilesTable) CountByEmail(id string) (int, error)

func (*FilesTable) DeleteOwnedBy

func (f *FilesTable) DeleteOwnedBy(id string) error

func (*FilesTable) GetEmailFiles

func (f *FilesTable) GetEmailFiles(id string) ([]*models.File, error)

func (*FilesTable) GetFile

func (f *FilesTable) GetFile(id string) (*models.File, error)

func (*FilesTable) GetFiles

func (f *FilesTable) GetFiles(ids ...string) ([]*models.File, error)

func (*FilesTable) GetInEmail

func (f *FilesTable) GetInEmail(owner string, email string, name string) ([]*models.File, error)

func (*FilesTable) GetOwnedBy

func (f *FilesTable) GetOwnedBy(id string) ([]*models.File, error)

type KeysTable

type KeysTable struct {
	RethinkCRUD
}

func (*KeysTable) FindByFingerprint

func (k *KeysTable) FindByFingerprint(fp string) (*models.Key, error)

func (*KeysTable) FindByOwner

func (k *KeysTable) FindByOwner(id string) ([]*models.Key, error)

type LabelsTable

type LabelsTable struct {
	RethinkCRUD
	Emails *EmailsTable
	//Cache   cache.Cache
	Expires time.Duration
}

func (*LabelsTable) Delete

func (l *LabelsTable) Delete(cond interface{}) error

Delete removes from db and cache using filter

func (*LabelsTable) DeleteID

func (l *LabelsTable) DeleteID(id string) error

DeleteID removes from db and cache using id query

func (*LabelsTable) GetLabel

func (l *LabelsTable) GetLabel(id string) (*models.Label, error)

func (*LabelsTable) GetLabelByNameAndOwner

func (l *LabelsTable) GetLabelByNameAndOwner(owner string, name string) (*models.Label, error)

func (*LabelsTable) GetOwnedBy

func (l *LabelsTable) GetOwnedBy(id string) ([]*models.Label, error)

GetOwnedBy returns all labels owned by id

func (*LabelsTable) Insert

func (l *LabelsTable) Insert(data interface{}) error

func (*LabelsTable) Update

func (l *LabelsTable) Update(data interface{}) error

Update clears all updated keys

func (*LabelsTable) UpdateID

func (l *LabelsTable) UpdateID(id string, data interface{}) error

UpdateID updates the specified label and updates cache

type ReservationsTable

type ReservationsTable struct {
	RethinkCRUD
}

ReservationsTable is a CRUD interface for accessing the "reservation" table

func (*ReservationsTable) IsEmailUsed

func (r *ReservationsTable) IsEmailUsed(email string) (bool, error)

func (*ReservationsTable) IsUsernameUsed

func (r *ReservationsTable) IsUsernameUsed(name string) (bool, error)

type RethinkCRUD

RethinkCRUD is the interface that every table should implement

type RethinkCreator

type RethinkCreator interface {
	Insert(data interface{}) error
}

RethinkCreator contains a function to create new instances in the table

type RethinkDeleter

type RethinkDeleter interface {
	Delete(pred interface{}) error
	DeleteID(id string) error
}

RethinkDeleter allows deleting resources from the database

type RethinkReader

type RethinkReader interface {
	Find(id string) (*gorethink.Cursor, error)
	FindFetchOne(id string, value interface{}) error

	FindBy(key string, value interface{}) (*gorethink.Cursor, error)
	FindByAndFetch(key string, value interface{}, results interface{}) error
	FindByAndFetchOne(key string, value interface{}, result interface{}) error
	FindByAndCount(key string, value interface{}) (int, error)

	Where(filter map[string]interface{}) (*gorethink.Cursor, error)
	WhereAndFetch(filter map[string]interface{}, results interface{}) error
	WhereAndFetchOne(filter map[string]interface{}, result interface{}) error

	FindByIndex(index string, values ...interface{}) (*gorethink.Cursor, error)
	FindByIndexFetch(results interface{}, index string, values ...interface{}) error
	FindByIndexFetchOne(result interface{}, index string, values ...interface{}) error
}

RethinkReader allows fetching resources from the database

type RethinkTable

type RethinkTable interface {
	GetTableName() string
	GetDBName() string
	GetTable() gorethink.Term
	GetSession() *gorethink.Session
}

RethinkTable contains the most basic table functions

type RethinkUpdater

type RethinkUpdater interface {
	Update(data interface{}) error
	UpdateID(id string, data interface{}) error
}

RethinkUpdater allows updating existing resources in the database

type ThreadsTable

type ThreadsTable struct {
	RethinkCRUD
}

func (*ThreadsTable) CountByLabel

func (t *ThreadsTable) CountByLabel(label string) (int, error)

func (*ThreadsTable) CountByLabelUnread

func (t *ThreadsTable) CountByLabelUnread(label string) (int, error)

func (*ThreadsTable) CountOwnedBy

func (t *ThreadsTable) CountOwnedBy(id string) (int, error)

func (*ThreadsTable) DeleteOwnedBy

func (t *ThreadsTable) DeleteOwnedBy(id string) error

func (*ThreadsTable) GetByLabel

func (t *ThreadsTable) GetByLabel(label string) ([]*models.Thread, error)

func (*ThreadsTable) GetOwnedBy

func (t *ThreadsTable) GetOwnedBy(id string) ([]*models.Thread, error)

func (*ThreadsTable) GetThread

func (t *ThreadsTable) GetThread(id string) (*models.Thread, error)

func (*ThreadsTable) List

func (t *ThreadsTable) List(
	owner string,
	sort []string,
	offset int,
	limit int,
	labels []string,
) ([]*models.Thread, error)

type TokensTable

type TokensTable struct {
	RethinkCRUD
	Cache   cache.Cache
	Expires time.Duration
}

TokensTable implements the CRUD interface for tokens

func (*TokensTable) Delete

func (t *TokensTable) Delete(cond interface{}) error

Delete removes from db and cache using filter

func (*TokensTable) DeleteID

func (t *TokensTable) DeleteID(id string) error

DeleteID removes from db and cache using id query

func (*TokensTable) DeleteOwnedBy

func (t *TokensTable) DeleteOwnedBy(id string) error

DeleteOwnedBy deletes all tokens owned by id

func (*TokensTable) FindFetchOne

func (t *TokensTable) FindFetchOne(id string, value interface{}) error

FindFetchOne tries cache and then tries using DefaultCRUD's fetch operation

func (*TokensTable) GetToken

func (t *TokensTable) GetToken(id string) (*models.Token, error)

GetToken returns a token with specified name

func (*TokensTable) Insert

func (t *TokensTable) Insert(data interface{}) error

Insert monkey-patches the DefaultCRUD method and introduces caching

func (*TokensTable) Update

func (t *TokensTable) Update(data interface{}) error

Update clears all updated keys

func (*TokensTable) UpdateID

func (t *TokensTable) UpdateID(id string, data interface{}) error

UpdateID updates the specified token and updates cache

Jump to

Keyboard shortcuts

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