clients

package
v0.2.9 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2019 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMongoDB

func NewMongoDB(url string, dbName string) base.Client

NewMongoDB instantiates and returns a ne MongoDB session object

func NewPostgres

func NewPostgres(url string) base.Client

NewPostgres instantiate and return a new PostgreSQL session object

func NewSQLServer

func NewSQLServer(url string) base.Client

NewSQLServer instantiate and return a new SQLServer session object

Types

type MongoDB

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

MongoDB is a client for the MongoDB

func (*MongoDB) Close

func (c *MongoDB) Close()

Close disconnect client from database and release the taken memory

func (*MongoDB) CreateTable

func (c *MongoDB) CreateTable(collectionName string, info base.TableInfo) error

CreateTable creates a `collectionName` collection. Since MongoDB is a schema-less database, creating a collection is not necessary before interacting with it and MongoDB creates collections automatically. Here you can create a collection with a special characteristics. You could use `mgo.CollectionInfo` tp specify these characteristics, and wrap it around `base.CollectionInfo` and pass it to this method. It is better use EnsureIndex for creating ordinary collection.

func (*MongoDB) DeleteByID

func (c *MongoDB) DeleteByID(collectionName string, id interface{}) error

DeleteByID finds a document in `collectionName` that its ID match with `id`, and remove it entirely. It will return error if anything went wrong.

func (*MongoDB) EnsureIndex

func (c *MongoDB) EnsureIndex(collectionName string, index base.Index) error

EnsureIndex ensures that given index is exists on given collection. If not, tries to create an index with given condition on given collection. EnsureIndex also creates the collection if it is not exists on DB.

func (*MongoDB) FindByID

func (c *MongoDB) FindByID(collectionName string, id interface{}) (base.RecordData, error)

FindByID searches through `collectionName` documents to find a doc that its ID match with `id` and returns it alongside any possible error.

func (*MongoDB) GetCollection

func (c *MongoDB) GetCollection(collection string) base.MongoCollection

GetCollection return collection instance with given name

func (*MongoDB) Insert

func (c *MongoDB) Insert(collectionName string, data *base.RecordData) error

Insert tries to insert `data` into `collectionName` and returns error if anything went wrong. `data` should pass by reference to have exact data on `collectionName`, otherwise updated record data isn't accessible.

func (*MongoDB) Query

func (c *MongoDB) Query(collectionName string, conditions ...base.Condition) base.QueryBuilder

Query generates and returns query object for further operations

func (*MongoDB) UpdateByID

func (c *MongoDB) UpdateByID(collectionName string, id interface{}, data base.RecordData) error

UpdateByID finds a document in `collectionName` that its ID match with `id`, and updates it with data. It will return error if anything went wrong.

type Postgres

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

Postgres is the PostgreSQL client

func (*Postgres) Close

func (c *Postgres) Close()

Close disconnect session from database and release the taken memory

func (*Postgres) CreateTable

func (c *Postgres) CreateTable(tableName string, info base.TableInfo) error

CreateTable creates `tableName` table with field and structure defined in `structure` parameter for each table fields

func (*Postgres) DeleteByID

func (c *Postgres) DeleteByID(tableName string, id interface{}) error

DeleteByID finds a record in `tableName` that its ID match with `id`, and remove it entirely. It will return error if anything went wrong.

func (*Postgres) EnsureIndex

func (c *Postgres) EnsureIndex(tableName string, index base.Index) error

EnsureIndex ensures that `index` is exists on `tableName` table, if not, it tries to create index with specified condition in `index` on `tableName`.

func (*Postgres) FindByID

func (c *Postgres) FindByID(tableName string, id interface{}) (base.RecordData, error)

FindByID searches through `tableName` records to find a row that its ID match with `id` and returns it alongside any possible error.

func (*Postgres) Insert

func (c *Postgres) Insert(tableName string, data *base.RecordData) error

Insert tries to insert `data` into `tableName` and returns error if anything went wrong. `data` should pass by reference to have exact data on `tableName`, otherwise updated record data isn't accessible.

func (*Postgres) Query

func (c *Postgres) Query(tableName string, conditions ...base.Condition) base.QueryBuilder

Query generates and returns sqlQuery object for further operations

func (*Postgres) UpdateByID

func (c *Postgres) UpdateByID(tableName string, id interface{}, data base.RecordData) error

UpdateByID finds a record in `tableName` that its ID match with `id`, and updates it with data. It will return error if anything went wrong.

type SQLServer

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

SQLServer is the Microsoft SQL Server session

func (*SQLServer) Close

func (c *SQLServer) Close()

Close disconnect session from database and release the taken memory

func (*SQLServer) CreateTable

func (c *SQLServer) CreateTable(tableName string, info base.TableInfo) error

CreateTable creates `tableName` table with field and structure defined in `structure` parameter for each table fields

func (*SQLServer) DeleteByID

func (c *SQLServer) DeleteByID(tableName string, id interface{}) error

DeleteByID finds a record in `tableName` that its ID match with `id`, and remove it entirely. It will return error if anything went wrong.

func (*SQLServer) EnsureIndex

func (c *SQLServer) EnsureIndex(tableName string, index base.Index) error

EnsureIndex ensures that `index` is exists on `tableName` table, if not, it tries to create index with specified condition in `index` on `tableName`.

func (*SQLServer) FindByID

func (c *SQLServer) FindByID(tableName string, id interface{}) (base.RecordData, error)

FindByID searches through `tableName` records to find a row that its ID match with `id` and returns it alongside any possible error.

func (*SQLServer) Insert

func (c *SQLServer) Insert(tableName string, data *base.RecordData) error

Insert tries to insert `data` into `tableName` and returns error if anything went wrong. `data` should pass by reference to have exact data on `tableName`, otherwise updated record data isn't accessible.

func (*SQLServer) Query

func (c *SQLServer) Query(tableName string, conditions ...base.Condition) base.QueryBuilder

Query generates and returns sqlQuery object for further operations

func (*SQLServer) UpdateByID

func (c *SQLServer) UpdateByID(tableName string, id interface{}, data base.RecordData) error

UpdateByID finds a record in `tableName` that its ID match with `id`, and updates it with data. It will return error if anything went wrong.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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