firestoreCRUD

package
Version: 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: 21 Imported by: 0

Documentation

Overview

package firestoreCRUD contains Firestore-specific code which can CRUD objects from the Firestore database.

There is also support for queries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

func Create(ctx context.Context, client *firestore.Client, queryable common.Queryable) error

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

This function has been deprecated.
func CreateData(ctx context.Context, client *firestore.Client, data *common.Data) error

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

func CreateSchema(ctx context.Context, client *firestore.Client, schema *common.Schema) error

CreateSchema creates a new Schema document and sets it. It DOES require that you've already generated an ID.

func Delete

func Delete(ctx context.Context, client *firestore.Client, queryable common.Queryable) error

Delete removes a document. Allows you to delete documents which do not exist.

func DeleteData

func DeleteData(ctx context.Context, client *firestore.Client, firestoreID string) error

DeleteData removes a document. Allows you to delete documents which do not exist.

func DeleteSchema

func DeleteSchema(ctx context.Context, client *firestore.Client, firestoreID string) error

DeleteSchema removes a document. Allows you to delete documents which do not exist.

func DeleteStorageObject

func DeleteStorageObject(bucketName string, objectName string) error

DeleteStorageObject deletes looks in the bucket at "bucketName" and deletes the object at "objectName".

func Deprecate

func Deprecate(ctx context.Context, client *firestore.Client, queryable common.Queryable) error

Deprecate sets the 'polyappDeprecated' property.

func DeprecateData

func DeprecateData(ctx context.Context, client *firestore.Client, firestoreID string) error

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

func DeprecateSchema(ctx context.Context, client *firestore.Client, firestoreID string) error

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 GetClient

func GetClient() (context.Context, *firestore.Client, error)

GetClient gets a client.

func GetKeyFromStorageObjectName

func GetKeyFromStorageObjectName(objectName string) string

func GetStorageObject

func GetStorageObject(bucketName string, objectName string) ([]byte, error)

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

func GetStorageObjectMetadata(bucketName string, objectName string) (map[string]string, error)

GetStorageObjectMetadata retrieves only the metadata for a Storage Object.

func GetStorageObjectName

func GetStorageObjectName(collectionName string, firestoreID string, key string) string

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

func ListStorageObjects(bucketName string, objectNamePrefix string) ([]string, error)

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 Read

func Read(ctx context.Context, client *firestore.Client, queryable common.Queryable) error

Read reads from Firestore into the Queryable object passed in.

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

func SetBytes(b []byte, firestoreID string, key string) error

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

func Update(ctx context.Context, client *firestore.Client, queryable common.Queryable) error

Update in Firestore. You must already know the document ID. Does not allow updating documents which do not exist.

func UpdateData

func UpdateData(ctx context.Context, client *firestore.Client, newData *common.Data) error

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

func UpdateSchema(ctx context.Context, client *firestore.Client, schema *common.Schema) error

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

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL