Documentation ¶
Index ¶
- func NewMongoDB(url string, dbName string) base.Client
- func NewPostgres(url string) base.Client
- func NewSQLServer(url string) base.Client
- type MongoDB
- func (c *MongoDB) Close()
- func (c *MongoDB) CreateTable(collectionName string, info base.TableInfo) error
- func (c *MongoDB) DeleteByID(collectionName string, id interface{}) error
- func (c *MongoDB) EnsureIndex(collectionName string, index base.Index) error
- func (c *MongoDB) FindByID(collectionName string, id interface{}) (base.RecordData, error)
- func (c *MongoDB) GetCollection(collection string) base.MongoCollection
- func (c *MongoDB) Insert(collectionName string, data *base.RecordData) error
- func (c *MongoDB) Query(collectionName string, conditions ...base.Condition) base.QueryBuilder
- func (c *MongoDB) UpdateByID(collectionName string, id interface{}, data base.RecordData) error
- type Postgres
- func (c *Postgres) Close()
- func (c *Postgres) CreateTable(tableName string, info base.TableInfo) error
- func (c *Postgres) DeleteByID(tableName string, id interface{}) error
- func (c *Postgres) EnsureIndex(tableName string, index base.Index) error
- func (c *Postgres) FindByID(tableName string, id interface{}) (base.RecordData, error)
- func (c *Postgres) Insert(tableName string, data *base.RecordData) error
- func (c *Postgres) Query(tableName string, conditions ...base.Condition) base.QueryBuilder
- func (c *Postgres) UpdateByID(tableName string, id interface{}, data base.RecordData) error
- type SQLServer
- func (c *SQLServer) Close()
- func (c *SQLServer) CreateTable(tableName string, info base.TableInfo) error
- func (c *SQLServer) DeleteByID(tableName string, id interface{}) error
- func (c *SQLServer) EnsureIndex(tableName string, index base.Index) error
- func (c *SQLServer) FindByID(tableName string, id interface{}) (base.RecordData, error)
- func (c *SQLServer) Insert(tableName string, data *base.RecordData) error
- func (c *SQLServer) Query(tableName string, conditions ...base.Condition) base.QueryBuilder
- func (c *SQLServer) UpdateByID(tableName string, id interface{}, data base.RecordData) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewMongoDB ¶
NewMongoDB instantiates and returns a ne MongoDB session object
func NewPostgres ¶
NewPostgres instantiate and return a new PostgreSQL session object
func NewSQLServer ¶
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 ¶
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 ¶
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 ¶
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) 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 ¶
CreateTable creates `tableName` table with field and structure defined in `structure` parameter for each table fields
func (*Postgres) DeleteByID ¶
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 ¶
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) 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 ¶
CreateTable creates `tableName` table with field and structure defined in `structure` parameter for each table fields
func (*SQLServer) DeleteByID ¶
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 ¶
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) 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.