Documentation ¶
Overview ¶
Пакет позволяет манипулировать записями в csv файлах с помощью sql-подобных запросов
Пример добавления новых записей в таблицу
r1 := make(csvstorage.CSVValueRecord) r1["id"] = "6" r1["title"] = "six" csvstorage.Insert("index").Values(r1).Do()
Пример создания схемы с помощью функции CreateCSVTableSchema
id := CSVField{"id", CSVFieldTypeInt} title := CSVField{"title", CSVFieldTypeText} CreateCSVTableSchema("table", id, title)
будут созданы два файла table.csv и table.schema
table.schema будет содержать:
id,int title,text
Пример использования составного where-условия:
simpleWhere1 := csvstorage.NewSimpleWhere("id", "<", "3") simpleWhere2 := csvstorage.NewSimpleWhere("content", "=", "четыре") complexWhere := csvstorage.NewComplexWhereCondition("OR", simpleWhere1, simpleWhere2) q := csvstorage.Select("content", "id").From("index").Where(complexWhere)
Index ¶
- Constants
- func CreateCSVTableSchema(table string, fields ...CSVField) error
- type CSVField
- type CSVTableSchema
- type CSVTableSchemaRecord
- type CSVValueRecord
- type DeleteQuery
- type InsertQuery
- type SelectQuery
- type SelectQueryResult
- type SelectQueryResultRecord
- type UpdateQuery
- type WhereComplexCondition
- type WhereCondition
- type WhereSimpleCondition
Constants ¶
const ( CSVFieldTypeInt = "int" CSVFieldTypeText = "text" )
Variables ¶
This section is empty.
Functions ¶
func CreateCSVTableSchema ¶
Types ¶
type CSVTableSchema ¶
type CSVTableSchema map[string]CSVTableSchemaRecord
func ReadSchema ¶
func ReadSchema(r io.Reader) CSVTableSchema
type CSVTableSchemaRecord ¶
type CSVTableSchemaRecord struct {
// contains filtered or unexported fields
}
type CSVValueRecord ¶
type DeleteQuery ¶
type DeleteQuery struct {
// contains filtered or unexported fields
}
Пример удаления записи с использование where
simpleWhere := csvstorage.NewSimpleWhere("id", "<", "3") csvstorage.Delete("index").Where(simpleWhere).Do()
func Delete ¶
func Delete(table string) *DeleteQuery
func (*DeleteQuery) Do ¶
func (this *DeleteQuery) Do()
func (*DeleteQuery) Where ¶
func (this *DeleteQuery) Where(where WhereCondition) *DeleteQuery
type InsertQuery ¶
type InsertQuery struct {
// contains filtered or unexported fields
}
func Insert ¶
func Insert(table string) *InsertQuery
func (*InsertQuery) Do ¶
func (this *InsertQuery) Do()
func (*InsertQuery) Values ¶
func (this *InsertQuery) Values(values ...CSVValueRecord) *InsertQuery
type SelectQuery ¶
type SelectQuery struct {
// contains filtered or unexported fields
}
func Select ¶
func Select(fields ...string) *SelectQuery
инициализация запроса, в качестве аргументов указываются поля для выборки
func (*SelectQuery) From ¶
func (this *SelectQuery) From(table string) *SelectQuery
указание таблицы, из которой будет производиться выборка
func (*SelectQuery) Limit ¶
func (this *SelectQuery) Limit(limit int) *SelectQuery
максимальное количество записей в результате запроса
func (*SelectQuery) Where ¶
func (this *SelectQuery) Where(cond WhereCondition) *SelectQuery
указание необходимых фильтров, с интерфейсом WhereCondition (см. csvwhere.go)
type SelectQueryResult ¶
type SelectQueryResult []SelectQueryResultRecord
type SelectQueryResultRecord ¶
type UpdateQuery ¶
type UpdateQuery struct {
// contains filtered or unexported fields
}
func Update ¶
func Update(table string) *UpdateQuery
func (*UpdateQuery) Do ¶
func (this *UpdateQuery) Do()
func (*UpdateQuery) Set ¶
func (this *UpdateQuery) Set(value CSVValueRecord) *UpdateQuery
func (*UpdateQuery) Where ¶
func (this *UpdateQuery) Where(where WhereCondition) *UpdateQuery
type WhereComplexCondition ¶
type WhereComplexCondition struct {
// contains filtered or unexported fields
}
сложное условие, может использовать логические операции AND, OR
func NewComplexWhereCondition ¶
func NewComplexWhereCondition(logicCond string, cond1, cond2 WhereCondition) WhereComplexCondition
func (WhereComplexCondition) Compute ¶
func (this WhereComplexCondition) Compute(record []string, schema CSVTableSchema) bool
type WhereCondition ¶
type WhereCondition interface {
Compute([]string, CSVTableSchema) bool
}
метод Compute должен выполнять фильтраци полей записи и указанных условий
type WhereSimpleCondition ¶
type WhereSimpleCondition struct {
// contains filtered or unexported fields
}
простое условие, с равенством/неравенством
func NewSimpleWhere ¶
func NewSimpleWhere(field, op, value string) WhereSimpleCondition
func (WhereSimpleCondition) Compute ¶
func (this WhereSimpleCondition) Compute(record []string, schema CSVTableSchema) bool