Documentation ¶
Overview ¶
package firestoreCRUD contains Firestore-specific code which can CRUD objects from the Firestore database.
There is also support for queries.
Index ¶
- func Create(ctx context.Context, client *firestore.Client, queryable common.Queryable) error
- func CreateData(ctx context.Context, client *firestore.Client, data *common.Data) errordeprecated
- func CreateDataContext(ctx context.Context, client *firestore.Client, polyappIndustryID string, ...) error
- func CreateSchema(ctx context.Context, client *firestore.Client, schema *common.Schema) error
- func Delete(ctx context.Context, client *firestore.Client, queryable common.Queryable) error
- func DeleteData(ctx context.Context, client *firestore.Client, firestoreID string) error
- func DeleteSchema(ctx context.Context, client *firestore.Client, firestoreID string) error
- func DeleteStorageObject(bucketName string, objectName string) error
- func Deprecate(ctx context.Context, client *firestore.Client, queryable common.Queryable) error
- func DeprecateData(ctx context.Context, client *firestore.Client, firestoreID string) error
- func DeprecateDataContext(ctx context.Context, client *firestore.Client, polyappIndustryID string, ...) error
- func DeprecateSchema(ctx context.Context, client *firestore.Client, firestoreID string) error
- func GetBlobBucket() string
- func GetClient() (context.Context, *firestore.Client, error)
- func GetKeyFromStorageObjectName(objectName string) string
- func GetStorageObject(bucketName string, objectName string) ([]byte, error)
- func GetStorageObjectArrayName(collectionName string, firestoreID string, key string, index int) string
- func GetStorageObjectMetadata(bucketName string, objectName string) (map[string]string, error)
- func GetStorageObjectName(collectionName string, firestoreID string, key string) string
- func ListStorageObjects(bucketName string, objectNamePrefix string) ([]string, error)
- func QueryRead(ctx context.Context, client *firestore.Client, industryID string, ...) (common.Iter, error)
- func Read(ctx context.Context, client *firestore.Client, queryable common.Queryable) error
- func ReadData(ctx context.Context, client *firestore.Client, firestoreID string) (common.Data, error)
- func ReadDataContext(ctx context.Context, client *firestore.Client, polyappIndustryID string, ...) (common.Iter, error)
- func ReadSchema(ctx context.Context, client *firestore.Client, firestoreID string) (common.Schema, error)
- func SetBytes(b []byte, firestoreID string, key string) error
- func SetStorageObject(bucketName string, data io.Reader, objectName string, ...) error
- func Update(ctx context.Context, client *firestore.Client, queryable common.Queryable) error
- func UpdateData(ctx context.Context, client *firestore.Client, newData *common.Data) error
- func UpdateDataContext(ctx context.Context, client *firestore.Client, polyappIndustryID string, ...) error
- func UpdateSchema(ctx context.Context, client *firestore.Client, schema *common.Schema) error
- type CombinedDBIterator
- type DBIterator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Create ¶
Create creates a new document and sets it. It DOES require that you've already generated an ID.
This is the generic function and should be used whenever possible.
func CreateData
deprecated
CreateData creates a new DataTypes document and sets it. It DOES require that you've already generated an ID.
If a document exists in the DB when this is called, it will be overwritten.
Deprecated: Use Create API instead.
func CreateDataContext ¶
func CreateDataContext(ctx context.Context, client *firestore.Client, polyappIndustryID string, polyappDomainID string, polyappSchemaID string, data *common.Data) error
CreateDataContext creates a single new document based on some schema information.
func CreateSchema ¶
CreateSchema creates a new Schema document and sets it. It DOES require that you've already generated an ID.
func DeleteData ¶
DeleteData removes a document. Allows you to delete documents which do not exist.
func DeleteSchema ¶
DeleteSchema removes a document. Allows you to delete documents which do not exist.
func DeleteStorageObject ¶
DeleteStorageObject deletes looks in the bucket at "bucketName" and deletes the object at "objectName".
func DeprecateData ¶
DeprecateData sets the 'polyappDeprecated' property.
func DeprecateDataContext ¶
func DeprecateDataContext(ctx context.Context, client *firestore.Client, polyappIndustryID string, polyappDomainID string, polyappSchemaID string) error
DeprecateDataContext deprecates a particular schema / schema in Polyapp. It does NOT delete the actual document.
func DeprecateSchema ¶
DeprecateSchema sets the 'polyappDeprecated' property.
func GetBlobBucket ¶
func GetBlobBucket() string
GetBlobBucket returns the name of the Google Cloud Bucket / S3 container / etc. into which to store blobs. This should be the same across all environments except for localhost, which won't have one.
func GetStorageObject ¶
GetStorageObject retrieves the "bucketName" bucket at object "objectName" and returns it as an array of bytes, the metadata, and an error (or not).
func GetStorageObjectArrayName ¶
func GetStorageObjectArrayName(collectionName string, firestoreID string, key string, index int) string
GetStorageObjectArrayName is similar to GetStorageObjectName, but it allows for arrays of [] bytes, and therefore supports the ABytes data type in Data.
index is used by [][]byte to indicate which index in the array this object is present at.
func GetStorageObjectMetadata ¶
GetStorageObjectMetadata retrieves only the metadata for a Storage Object.
func GetStorageObjectName ¶
GetStorageObjectName can turn a collection name like "data", a firestore ID for the Data document, and the object's key in .Bytes into the storage object name in GCP.
func ListStorageObjects ¶
ListStorageObjects gets a list of "objectName" with a particular prefix and returns it as an array of strings.
func QueryRead ¶
func QueryRead(ctx context.Context, client *firestore.Client, industryID string, domainID string, schemaID string, query firestore.Query) (common.Iter, error)
QueryRead runs a generic Query and gives you common.Iter to operate over the results. common.Iter figures out what type of Queryable to return in 'Next()' by looking at the Query Schema.
Side note: There used to be QueryUpdate and QueryDelete functions too. Now if you wish to perform such operations, first use QueryRead and then iterate over each document & update / delete them individually.
func ReadData ¶
func ReadData(ctx context.Context, client *firestore.Client, firestoreID string) (common.Data, error)
ReadData reads from Firestore into a Data object.
func ReadDataContext ¶
func ReadDataContext(ctx context.Context, client *firestore.Client, polyappIndustryID string, polyappDomainID string, polyappSchemaID string) (common.Iter, error)
ReadDataContext reads from Firestore into data based on some schema information. Because there will be many matching documents for this query, an iterator is returned giving access to those documents.
func ReadSchema ¶
func ReadSchema(ctx context.Context, client *firestore.Client, firestoreID string) (common.Schema, error)
ReadSchema reads from Firestore into a Schema object.
func SetBytes ¶
SetBytes creates new storage objects. If there is an existing storage object with that name it is overwritten.
func SetStorageObject ¶
func SetStorageObject(bucketName string, data io.Reader, objectName string, metadata map[string]string) error
SetStorageObject sets the "bucketName" bucket with objectName "objectName" with all of the readable data in 'data'.
func Update ¶
Update in Firestore. You must already know the document ID. Does not allow updating documents which do not exist.
func UpdateData ¶
UpdateData in Firestore. You must already know the document ID. Does not allow updating documents which do not exist. The input Data struct must be valid.
func UpdateDataContext ¶
func UpdateDataContext(ctx context.Context, client *firestore.Client, polyappIndustryID string, polyappDomainID string, polyappSchemaID string, data *common.Data) error
UpdateDataContext iterates over all matching Firestore documents and updates all of them to match data *common.Data with a merge operation. I suspect this will be helpful for schema conversions.
func UpdateSchema ¶
UpdateSchema in Firestore. You must already know the document ID. Does not allow updating documents which do not exist. Unlike other Update functions, UpdateSchema does not MergeAll - it just replaces. This means your input Schema must be valid.
This function exists because it is using Merge which is not easy to support with interfaces.
Types ¶
type CombinedDBIterator ¶
type CombinedDBIterator struct {
// contains filtered or unexported fields
}
func CreateCombinedDBIterator ¶
func CreateCombinedDBIterator(iters []*firestore.DocumentIterator, lengthOfResults []int) *CombinedDBIterator
CreateCombinedDBIterator creates an iterator which can operate over any Queryable type. This one is coupled to Firestore.
func (*CombinedDBIterator) Length ¶
func (d *CombinedDBIterator) Length() int
Length of the results.
func (*CombinedDBIterator) Next ¶
func (d *CombinedDBIterator) Next() (common.Queryable, error)
Next returns the next result. Its second return value is iterator.Done if there are no more results. Once Next returns Done, all subsequent calls will return Done.
func (*CombinedDBIterator) Stop ¶
func (d *CombinedDBIterator) Stop()
Stop stops the iterator, freeing its resources. Always call Stop when you are done with a DocumentIterator. It is not safe to call Stop concurrently with Next.
type DBIterator ¶
type DBIterator struct {
// contains filtered or unexported fields
}
func CreateDBIterator ¶
func CreateDBIterator(iter *firestore.DocumentIterator, lengthOfResults int) *DBIterator
CreateDBIterator creates an iterator which can operate over any Queryable type. This one is coupled to Firestore.
func (*DBIterator) Length ¶
func (d *DBIterator) Length() int
Length of the results. Returns -1 if we don't know the length.
func (*DBIterator) Next ¶
func (d *DBIterator) Next() (common.Queryable, error)
Next returns the next result. Its second return value is iterator.Done if there are no more results. Once Next returns Done, all subsequent calls will return Done.
func (*DBIterator) Stop ¶
func (d *DBIterator) Stop()
Stop stops the iterator, freeing its resources. Always call Stop when you are done with a DocumentIterator. It is not safe to call Stop concurrently with Next.