allDB

package
v0.0.0-...-646b7d3 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2021 License: MIT Imports: 16 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyData

func CopyData(data *common.Data) (copies []common.Data, err error)

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

func Create(q common.Queryable) error

Create a queryable in the database. This function currently only supports common.Data.

func CreateAction

func CreateAction(action *common.Action) error

CreateAction is a CRUD request to the Action collection

func CreateBot

func CreateBot(bot *common.Bot) error

CreateBot is a CRUD request to the Bot collection

func CreateCSS

func CreateCSS(CSS *common.CSS) error

CreateCSS is a CRUD request to the CSS collection

func CreateData deprecated

func CreateData(data *common.Data) error

CreateData is a CRUD request to the Data collection

Deprecated: Use Create API instead.

func CreatePublicMap

func CreatePublicMap(publicMap *common.PublicMap) error

CreatePublicMap is a CRUD request to the PublicMap collection

func CreateRole

func CreateRole(role *common.Role) error

CreateRole is a CRUD request to the Role collection

func CreateSchema

func CreateSchema(schema *common.Schema) error

CreateSchema is a CRUD request to the Schema collection

func CreateTask

func CreateTask(task *common.Task) error

CreateTask is a CRUD request to the Task collection

func CreateUX

func CreateUX(ux *common.UX) error

CreateUX is a CRUD request to the UX collection

func CreateUser

func CreateUser(user *common.User) error

CreateUser is a CRUD request to the User collection

func DataIntoStructureComplex

func DataIntoStructureComplex(data *common.Data, ptrToStructure interface{}) error

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

func DeleteAction(firestoreID string) error

DeleteAction is a CRUD request to the Action collection

func DeleteBot

func DeleteBot(firestoreID string) error

DeleteBot is a CRUD request to the Bot collection

func DeleteCSS

func DeleteCSS(firestoreID string) error

DeleteCSS is a CRUD request to the CSS collection

func DeleteData

func DeleteData(firestoreID string) error

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

func DeleteDataAndChildren(dataID string) error

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

func DeletePublicMap(firestoreID string) error

DeletePublicMap is a CRUD request to the PublicMap collection

func DeleteRole

func DeleteRole(firestoreID string) error

DeleteRole is a CRUD request to the Role collection

func DeleteSchema

func DeleteSchema(firestoreID string) error

DeleteSchema is a CRUD request to the Schema collection

func DeleteTask

func DeleteTask(firestoreID string) error

DeleteTask is a CRUD request to the Task collection

func DeleteUX

func DeleteUX(firestoreID string) error

DeleteUX is a CRUD request to the UX collection

func DeleteUser

func DeleteUser(firestoreID string) error

DeleteUser is a CRUD request to the User collection

func QueryEquals

func QueryEquals(firestoreCollection string, key string, value string) (common.Queryable, error)

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

func Read(q common.Queryable) error

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

func ReadAction(firestoreID string) (common.Action, error)

ReadAction is a CRUD request to the Action collection

func ReadBot

func ReadBot(firestoreID string) (common.Bot, error)

ReadBot is a CRUD request to the Bot collection

func ReadCSS

func ReadCSS(firestoreID string) (common.CSS, error)

ReadCSS is a CRUD request to the CSS collection

func ReadData deprecated

func ReadData(firestoreID string) (common.Data, error)

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

func ReadDataABytes(firestoreID string, key string) ([][]byte, error)

ReadDataABytes returns the byte objects at the given key.

func ReadDataAndChildren

func ReadDataAndChildren(dataID string) ([]common.Data, error)

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

func ReadDataBytes(firestoreID string, key string) ([]byte, error)

ReadDataBytes returns the byte object at the given key.

func ReadPublicMap

func ReadPublicMap(firestoreID string) (common.PublicMap, error)

ReadPublicMap is a CRUD request to the PublicMap collection

func ReadRole

func ReadRole(firestoreID string) (common.Role, error)

ReadRole is a CRUD request to the Role collection

func ReadSchema

func ReadSchema(firestoreID string) (common.Schema, error)

ReadSchema is a CRUD request to the Schema collection

func ReadTask

func ReadTask(firestoreID string) (common.Task, error)

ReadTask is a CRUD request to the Task collection

func ReadUX

func ReadUX(firestoreID string) (common.UX, error)

ReadUX is a CRUD request to the UX collection

func ReadUser

func ReadUser(firestoreID string) (common.User, error)

ReadUser is a CRUD request to the User collection

func UpdateAction

func UpdateAction(action *common.Action) error

UpdateAction is a CRUD request to the Action collection

func UpdateBot

func UpdateBot(bot *common.Bot) error

UpdateBot is a CRUD request to the Bot collection

func UpdateCSS

func UpdateCSS(CSS *common.CSS) error

UpdateCSS is a CRUD request to the CSS collection

func UpdateData

func UpdateData(data *common.Data) error

UpdateData is a CRUD request to the Data collection

func UpdatePublicMap

func UpdatePublicMap(publicMap *common.PublicMap) error

UpdatePublicMap is a CRUD request to the PublicMap collection

func UpdateRole

func UpdateRole(role *common.Role) error

UpdateRole is a CRUD request to the Role collection

func UpdateSchema

func UpdateSchema(schema *common.Schema) error

UpdateSchema is a CRUD request to the Schema collection

func UpdateTask

func UpdateTask(task *common.Task) error

UpdateTask is a CRUD request to the Task collection

func UpdateUX

func UpdateUX(ux *common.UX) error

UpdateUX is a CRUD request to the UX collection

func UpdateUser

func UpdateUser(user *common.User) error

UpdateUser is a CRUD request to the User collection

func UpdateUserPassword

func UpdateUserPassword(user *common.User, newPassword string) error

UpdateUserPassword updates the User's password. Passwords have special handling.

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

func (q *Query) AddArrayContains(k string, v string) error

AddArrayContains adds a search for the value 'v' in the array 'k'

func (*Query) AddEquals

func (q *Query) AddEquals(k string, v string)

AddEquals adds a condition to the query results that the key k must equal the string v.

func (*Query) AddSortBy

func (q *Query) AddSortBy(k string, AscDesc string) error

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

func (q *Query) QueryRead() (common.Iter, error)

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) SetLength

func (q *Query) SetLength(length int)

SetLength sets the maximum number of documents we are returning.

func (*Query) SetOffset

func (q *Query) SetOffset(n int)

SetOffset is extremely expensive. Sorry.

func (*Query) SetStartAfterDocumentID

func (q *Query) SetStartAfterDocumentID(id string)

SetStartAfterDocumentID is the last row in the last query results. We need to start our new query after this document.

Jump to

Keyboard shortcuts

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