Documentation ¶
Overview ¶
Package allDB rests just above the CRUD layer which is a series of packages handling different databases and caches. Requests to this package's APIs (aka exported functions) are database-agnostic and application-specific, like a request for a specific structure or a query for a list of documents. This layer returns a 'common' package data structure which isn't specific to any one database.
The internals of this package may be a bit complicated. If the request is to the Data or User collections the data and control paths plunge quickly through this layer, perhaps stopping at a cache. Changes to the Schema require several other steps: TODO implement these other steps First, schema changes mean we need to create a new schema on the database and ensure they are linked to each other. Second, we need to decide what the 'master' schema is. For now let's assume it's the original schema. Third, there needs to be a conversion from the 'master' schema to the new schema and a conversion from the new schema back to the 'master' schema. Fourth, requests to data documents which are not using the 'master' schema need to have their data converted before that data is sent out from this layer.
Why is all of that necessary? Many companies force their data to hold one single schema and convert all data to that schema when the update occurs. There are two problems with that approach. First the data model becomes inflexible for users which in turn restricts user's ability to make significant updates to their own tasks without a software developer helping them, which is then prohibitively expensive. Second, conversions on large amounts of data are often done all at once when new software is deployed. I don't want to wait for such conversions to occur before the software becomes available. Incremental conversions are the solution to this problem since they can run while there are several versions of a schema in use.
One other note: This package is supposed to be used both on the client (JS / WASM) and on the server and in both cases its outputs should be identical. Consequently some files are built conditionally and this package's tests need to be run with both GOOS / GOARCH. However, at this time the JS / WASM code doesn't work yet.
Index ¶
- func CopyData(data *common.Data) (copies []common.Data, err error)
- func Create(q common.Queryable) error
- func CreateAction(action *common.Action) error
- func CreateBot(bot *common.Bot) error
- func CreateCSS(CSS *common.CSS) error
- func CreateData(data *common.Data) errordeprecated
- func CreatePublicMap(publicMap *common.PublicMap) error
- func CreateRole(role *common.Role) error
- func CreateSchema(schema *common.Schema) error
- func CreateTask(task *common.Task) error
- func CreateUX(ux *common.UX) error
- func CreateUser(user *common.User) error
- func DataIntoStructureComplex(data *common.Data, ptrToStructure interface{}) error
- func DeleteAction(firestoreID string) error
- func DeleteBot(firestoreID string) error
- func DeleteCSS(firestoreID string) error
- func DeleteData(firestoreID string) error
- func DeleteDataAndChildren(dataID string) error
- func DeletePublicMap(firestoreID string) error
- func DeleteRole(firestoreID string) error
- func DeleteSchema(firestoreID string) error
- func DeleteTask(firestoreID string) error
- func DeleteUX(firestoreID string) error
- func DeleteUser(firestoreID string) error
- func QueryEquals(firestoreCollection string, key string, value string) (common.Queryable, error)
- func Read(q common.Queryable) error
- func ReadAction(firestoreID string) (common.Action, error)
- func ReadBot(firestoreID string) (common.Bot, error)
- func ReadCSS(firestoreID string) (common.CSS, error)
- func ReadData(firestoreID string) (common.Data, error)deprecated
- func ReadDataABytes(firestoreID string, key string) ([][]byte, error)
- func ReadDataAndChildren(dataID string) ([]common.Data, error)
- func ReadDataBytes(firestoreID string, key string) ([]byte, error)
- func ReadPublicMap(firestoreID string) (common.PublicMap, error)
- func ReadRole(firestoreID string) (common.Role, error)
- func ReadSchema(firestoreID string) (common.Schema, error)
- func ReadTask(firestoreID string) (common.Task, error)
- func ReadUX(firestoreID string) (common.UX, error)
- func ReadUser(firestoreID string) (common.User, error)
- func UpdateAction(action *common.Action) error
- func UpdateBot(bot *common.Bot) error
- func UpdateCSS(CSS *common.CSS) error
- func UpdateData(data *common.Data) error
- func UpdatePublicMap(publicMap *common.PublicMap) error
- func UpdateRole(role *common.Role) error
- func UpdateSchema(schema *common.Schema) error
- func UpdateTask(task *common.Task) error
- func UpdateUX(ux *common.UX) error
- func UpdateUser(user *common.User) error
- func UpdateUserPassword(user *common.User, newPassword string) error
- type AllDBQuery
- type Query
- func (q *Query) AddArrayContains(k string, v string) error
- func (q *Query) AddEquals(k string, v string)
- func (q *Query) AddSortBy(k string, AscDesc string) error
- func (q *Query) Init(industryID string, domainID string, schemaID string, ...)
- func (q *Query) QueryRead() (common.Iter, error)
- func (q *Query) SetLength(length int)
- func (q *Query) SetOffset(n int)
- func (q *Query) SetStartAfterDocumentID(id string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CopyData ¶
CopyData copies a Data document and all of its Ref and ARef children into a new array of Datas, where the first Data is the parent, the subsequent Datas are Refs, and the final Datas are ARefs. It does not go more than 1 Ref layer down - aka it is not recursive.
This function sets the FirestoreID of every Data to a new value so it is safe to directly save the result to the database.
CopyData does read child Refs from the database in parallel. It does NOT save anything to the database. This is because it is assumed that the copies will need to be modified slightly before storage and if we saved them to the database here, you would have to perform multiple writes within 1 second when you make the subsequent update. Since multiple writes in 1 second are not supposed to be allowed by Firestore, this function returns copies without writing them to the DB.
func Create ¶
Create a queryable in the database. This function currently only supports common.Data.
func CreateAction ¶
CreateAction is a CRUD request to the Action collection
func CreateData
deprecated
func CreatePublicMap ¶
CreatePublicMap is a CRUD request to the PublicMap collection
func CreateRole ¶
CreateRole is a CRUD request to the Role collection
func CreateSchema ¶
CreateSchema is a CRUD request to the Schema collection
func CreateTask ¶
CreateTask is a CRUD request to the Task collection
func CreateUser ¶
CreateUser is a CRUD request to the User collection
func DataIntoStructureComplex ¶
DataIntoStructureComplex is similar to DataIntoStructure, except it also handles embedded structs and embedded lists of structs. This means it is a great tool to transform a common.Data into an arbitrary structure.
For example, the following type would be fully populated: type A struct { Title string Fields []Field SomethingElse []Something `suffix:"Something Else"` }
TODO write tests for this
func DeleteAction ¶
DeleteAction is a CRUD request to the Action collection
func DeleteData ¶
DeleteData is a CRUD request to the Data collection.
No error is thrown if the data does not exist in one or more databases.
func DeleteDataAndChildren ¶
DeleteDataAndChildren deletes a Data Document ID and all of its Ref and ARef children.
It does not go more than 1 Ref layer down - aka it is not recursive.
func DeletePublicMap ¶
DeletePublicMap is a CRUD request to the PublicMap collection
func DeleteRole ¶
DeleteRole is a CRUD request to the Role collection
func DeleteSchema ¶
DeleteSchema is a CRUD request to the Schema collection
func DeleteTask ¶
DeleteTask is a CRUD request to the Task collection
func DeleteUser ¶
DeleteUser is a CRUD request to the User collection
func QueryEquals ¶
QueryEquals returns at most one common.Queryable where key == value, or nil if no Queryable was found. If more than one Queryable is returned for this key == value an error is thrown.
func Read ¶
Read populates the Queryable. If the object contains []byte or [][]byte like common.Data, those fields are not loaded into the result. To access those fields, please call ReadBytes(key) or ReadABytes(key).
func ReadAction ¶
ReadAction is a CRUD request to the Action collection
func ReadData
deprecated
ReadData is a CRUD request to the Data collection. It assumes that data in the database is in the master schema format. TODO when the DB is not always in master schema format, this will need to call a conversion function on the returned readData.
Deprecated: Use Read API instead.
func ReadDataABytes ¶
ReadDataABytes returns the byte objects at the given key.
func ReadDataAndChildren ¶
ReadDataAndChildren returns a Data Document and all of its Ref and ARef children. The first Data is for the dataID passed in to the function. The others may be out of order.
It does not go more than 1 Ref layer down - aka it is not recursive.
func ReadDataBytes ¶
ReadDataBytes returns the byte object at the given key.
func ReadPublicMap ¶
ReadPublicMap is a CRUD request to the PublicMap collection
func ReadSchema ¶
ReadSchema is a CRUD request to the Schema collection
func UpdateAction ¶
UpdateAction is a CRUD request to the Action collection
func UpdateData ¶
UpdateData is a CRUD request to the Data collection
func UpdatePublicMap ¶
UpdatePublicMap is a CRUD request to the PublicMap collection
func UpdateRole ¶
UpdateRole is a CRUD request to the Role collection
func UpdateSchema ¶
UpdateSchema is a CRUD request to the Schema collection
func UpdateTask ¶
UpdateTask is a CRUD request to the Task collection
func UpdateUser ¶
UpdateUser is a CRUD request to the User collection
Types ¶
type AllDBQuery ¶
type AllDBQuery = Query
AllDBQuery is deprecated because allDB.AllDBQuery stutters. Use Query as allDB.Query instead.
type Query ¶
type Query struct { // IndustryID is the name of the industry the query will be run against. This is required for Data FirestoreCollection // since fields are prefixed with industry_domain_schema. IndustryID string // DomainID is the name of the domain the query will be run against. This is required for Data FirestoreCollection // since fields are prefixed with industry_domain_schema. DomainID string // Schema is the name of the schema the query will be performed across. This is required for Data FirestoreCollection // since fields are prefixed with industry_domain_schema. Schema string // FirestoreCollection is the name of the firestore collection to perform the query across, like "ux" or "schema" FirestoreCollection string // Equals requires that in a given document, the key k must equal the value v. // If this condition is not met the document is not returned. Equals map[string]interface{} // ArrayContains is a search for the value 'v' in the array 'k' ArrayContains map[string]string // SortBy is an ordered list of column keys to sort by. SortBy []string // SortDirection is an ordered list of directions to sort by - either "asc" or "desc" SortDirection []string // StartAfterDocumentID is the last document ID in the previous table. StartAfterDocumentID string // Offset is extremely inefficient. Offset int // Length is the number of documents to return. Length int }
Query implements common.Query via: &Query.
func (*Query) AddArrayContains ¶
AddArrayContains adds a search for the value 'v' in the array 'k'
func (*Query) AddEquals ¶
AddEquals adds a condition to the query results that the key k must equal the string v.
func (*Query) AddSortBy ¶
AddSortBy declares how the output data should be ordered. k is key and AscDesc is either asc or desc. This only applies to QueryRead() calls.
func (*Query) Init ¶
func (q *Query) Init(industryID string, domainID string, schemaID string, firestoreCollection string)
Init ensures this Query will pass validation. FirestoreCollection is always required, but Industry, Domain, and SchemaID are not necessarily required, depending on the collection being queried. They are definitely required for the Data collection.
func (*Query) QueryRead ¶
QueryRead retrieves all Data matching the request conditions.
To view the next document in the query results call q.Next()
The request is over if err == common.IterDone
func (*Query) SetStartAfterDocumentID ¶
SetStartAfterDocumentID is the last row in the last query results. We need to start our new query after this document.