Database
Represents a Sphere Kit database.
Constructor
Initialise the database class using the ID of the database. If the database you are trying to access is linked to your project in the Sphere Kit Dashboard, you can omit the id parameter.
var myDatabase = new Database(); // Initialising this project's database
var otherDatabase = new Database("databaseId") // Initialising another project's databaseMethods
Path parts and field names must not contain forward slashes ( / ), and cannot start with underscores ( _ ) or dollar signs ($). Additionally, path parts cannot contain spaces. The total length of the document path cannot exceed 230 characters.
CollectionFromPath(string path)
Returns a collection reference for the given path. Use with caution, as the path is not validated and can lead to injected paths if not properly sanitized.
Not recommended: Use the Collection() method for protection against injection attacks and increased clarity.
Parameters:
string path: The full path to the collection.
Returns: CollectionReference : A collection reference to the collection at this path.
Example
var locationABoxesRef = myDatabase.CollectionFromPath("locations/a/boxes");Possible exceptions
ArgumentException
If the path is invalid.
DocumentFromPath(string path)
Returns a document reference for the given path. Use with caution, as the path is not validated and can lead to injected paths if not properly sanitized.
Not recommended: Use the Document() method on a CollectionReference for protection against injection attacks and increased clarity.
Parameters:
string path: The full path to the document.
Returns: DocumentReference : A document reference to the document at this path.
Example
var locationARef = myDatabase.Document("locations/a");Possible exceptions
ArgumentException
If the path is invalid.
Collection(string id)
Returns a collection reference for the given path part. Validates the path part to ensure it does not contain slashes (preventing injection attacks) and meets other requirements.
Parameters:
string id: The ID of the collection
Returns: CollectionReference : A collection reference to the collection with this ID.
Example
var locationsRef = myDatabase.Collection("locations");Possible exceptions
ArgumentException
If the ID is invalid or contains slashes (which can cause injection attacks).
Last updated