Multiplayer Reference
Class DatabaseObject
Namespace: PlayerIO.GameLibrary
Language: C# / .NET
This class represents a BigDB Database Object that has a Key and a collection of named properties.
There are methods for setting, getting, and removing properties, and changes to the object can be persisted to BigDB with the Save() method.
Database objects are very similar to JSON objects and are most easily visualized as such. For example, we can visualize a car object like this:
If we then want to create this object in BigDB, we would have to do this:
To make it easier to work with nested objects, you can reference them directly by separating the property names with a dot. Using this, we can set the stats properties of the car like this instead:
When you want to read properties from a database object, you have to call the corresponding get method indicating the type of the property.
BigDB doesn't enforce anything on your objects. Two objects in the same table do not need to have the same properties set, and do not need to have the same type on the same property. If you try to get a property that is missing, or if you are using a get method of the wrong type, you will get an exception.
One way of avoiding this is to first check the object if a certain property exists before reading this. You can do this with the Contains method.
Another way of avoiding errors is to specify a default value when calling a get method. If the object doesn't contain the property, the method will return your default value instead.
You can also easily remove properties from your object with the Remove method.
Finally, to persist any changes you've made to an object you can call the Save method. Note that you can only call Save on an object that exist in the database. This means that the first time you save an object you have to call the PlayerIO.BigDB.CreateObject method, but all subsequent times you can call the Save method. There is also a property called ExistsInDatabase that you can use to check if it has been created or not.
The Save method is asynchronous just like the CreateObject method in PlayerIO.BigDB, and you can specify a callback if you wish to do something when the object actually has been saved.
Properties | |||
---|---|---|---|
public int |
Returns the number of properties on this object |
||
public bool |
Returns true if the object has been persisted |
||
public string |
The key of the object. |
||
public ICollection<string> |
Get the names of all properties on this object |
||
public string |
The name of the BigDB table this object belongs to |
||
Methods | |||
public void |
Removes all properties on this object |
||
public bool |
Returns true if the given property exists on this object |
||
public DatabaseArray |
Get the given array property |
||
public bool |
Get the given bool property, falling back to the given default value if the bool property does not exist |
||
public bool |
Get the given bool property |
||
public Byte[] |
Get the given byte array property, falling back to the given default value if the byte array property does not exist |
||
public Byte[] |
Get the given byte array property |
||
public DateTime |
Get the given datetime property |
||
public DateTime |
Get the given datetime property, falling back to the given default value if the datetime property does not exist |
||
public Double |
Get the given double property |
||
public Double |
Get the given double property, falling back to the given default value if the double property does not exist |
||
public Single |
Get the given float property, falling back to the given default value if the float property does not exist |
||
public Single |
Get the given float property |
||
public int |
Get the given int property, falling back to the given default value if the int property does not exist |
||
public int |
Get the given int property |
||
public Int64 |
Get the given long property, falling back to the given default value if the long property does not exist |
||
public Int64 |
Get the given long property |
||
public DatabaseObject |
Get the given object property |
||
public string |
Get the given string property, falling back to the given default value if the string property does not exist |
||
public string |
Get the given string property |
||
public uint |
Get the given uint property, falling back to the given default value if the uint property does not exist |
||
public uint |
Get the given uint property |
||
public object |
Get the given property as an object |
||
public DatabaseObject |
Removes the value of the given property from this object |
||
public void |
Persist the object to the database |
||
public void |
Persist the object to the database |
||
public void |
Persist the object to the database asynchronously, using optimistic locking if specified |
||
public void |
Persist the object to the database asynchronously, using optimistic locking and full overwrite if specified |
||
public void |
Persist the object to the database asynchronously. |
||
public void |
Persist the object to the database, using optimistic locking and full overwrite if specified |
||
public void |
Persist the object to the database, using optimistic locking if specified |
||
public void |
Persist the object to the database, using optimistic locking if specified |
||
public void |
Persist the object to the database, using optimistic locking and full overwrite if specified |
||
public DatabaseObject |
Set the given property to the given object |
||
public DatabaseObject |
Set the given property to the given array |
||
public DatabaseObject |
Set the given property to the given string value |
||
public DatabaseObject |
Set the given property to the given datetime value |
||
public DatabaseObject |
Set the given property to the given long value |
||
public DatabaseObject |
Set the given property to the given uint value |
||
public DatabaseObject |
Set the given property to the given int value |
||
public DatabaseObject |
Set the given property to the given bool value |
||
public DatabaseObject |
Set the given property to the given byte array value |
||
public DatabaseObject |
Set the given property to the given double value |
||
public DatabaseObject |
Set the given property to the given float value |
DatabaseObject.Count
public int |
|
Returns the number of properties on this object
DatabaseObject.ExistsInDatabase
public bool |
|
Returns true if the object has been persisted
DatabaseObject.Key
public string |
|
The key of the object.
DatabaseObject.Properties
public ICollection<string> |
|
Get the names of all properties on this object
DatabaseObject.Table
public string |
|
The name of the BigDB table this object belongs to
DatabaseObject.Clear
public void |
|
Removes all properties on this object
DatabaseObject.Contains
public bool |
|
Returns true if the given property exists on this object
Arguments
string | propertyExpression |
DatabaseObject.GetArray
public DatabaseArray |
|
Get the given array property
Arguments
string | propertyExpression |
DatabaseObject.GetBool
public bool |
|
Get the given bool property, falling back to the given default value if the bool property does not exist
Arguments
string | propertyExpression |
bool | defaultValue |
DatabaseObject.GetBool
public bool |
|
Get the given bool property
Arguments
string | propertyExpression |
DatabaseObject.GetBytes
public Byte[] |
|
Get the given byte array property, falling back to the given default value if the byte array property does not exist
Arguments
string | propertyExpression |
Byte[] | defaultValue |
DatabaseObject.GetBytes
public Byte[] |
|
Get the given byte array property
Arguments
string | propertyExpression |
DatabaseObject.GetDateTime
public DateTime |
|
Get the given datetime property
Arguments
string | propertyExpression |
DatabaseObject.GetDateTime
public DateTime |
|
Get the given datetime property, falling back to the given default value if the datetime property does not exist
Arguments
string | propertyExpression |
DateTime | defaultValue |
DatabaseObject.GetDouble
public Double |
|
Get the given double property
Arguments
string | propertyExpression |
DatabaseObject.GetDouble
public Double |
|
Get the given double property, falling back to the given default value if the double property does not exist
Arguments
string | propertyExpression |
Double | defaultValue |
DatabaseObject.GetFloat
public Single |
|
Get the given float property, falling back to the given default value if the float property does not exist
Arguments
string | propertyExpression |
Single | defaultValue |
DatabaseObject.GetFloat
public Single |
|
Get the given float property
Arguments
string | propertyExpression |
DatabaseObject.GetInt
public int |
|
Get the given int property, falling back to the given default value if the int property does not exist
Arguments
string | propertyExpression |
int | defaultValue |
DatabaseObject.GetInt
public int |
|
Get the given int property
Arguments
string | propertyExpression |
DatabaseObject.GetLong
public Int64 |
|
Get the given long property, falling back to the given default value if the long property does not exist
Arguments
string | propertyExpression |
Int64 | defaultValue |
DatabaseObject.GetLong
public Int64 |
|
Get the given long property
Arguments
string | propertyExpression |
DatabaseObject.GetObject
public DatabaseObject |
|
Get the given object property
Arguments
string | propertyExpression |
DatabaseObject.GetString
public string |
|
Get the given string property, falling back to the given default value if the string property does not exist
Arguments
string | propertyExpression |
string | defaultValue |
DatabaseObject.GetString
public string |
|
Get the given string property
Arguments
string | propertyExpression |
DatabaseObject.GetUInt
public uint |
|
Get the given uint property, falling back to the given default value if the uint property does not exist
Arguments
string | propertyExpression |
uint | defaultValue |
DatabaseObject.GetUInt
public uint |
|
Get the given uint property
Arguments
string | propertyExpression |
DatabaseObject.GetValue
public object |
|
Get the given property as an object
Arguments
string | propertyExpression |
DatabaseObject.Remove
public DatabaseObject |
|
Removes the value of the given property from this object
Arguments
string | propertyExpression |
DatabaseObject.Save
public void |
|
Persist the object to the database
Arguments
Callback | successCallback |
Callback when the save succeeds | |
Callback<PlayerIOError> | errorCallback |
Callback that will be called instead of successCallback if an error occurs during the save. |
DatabaseObject.Save
public void |
|
Persist the object to the database
Arguments
Callback | successCallback |
Callback when the save succeeds |
DatabaseObject.Save
public void |
|
Persist the object to the database asynchronously, using optimistic locking if specified
If use the overloads with success callbacks if you need to know when the save has completed successfully
Arguments
bool | useOptimisticLock |
If true, the save will only be completed if the database object has not changed in BigDB since this instance was loaded. |
DatabaseObject.Save
public void |
|
Persist the object to the database asynchronously, using optimistic locking and full overwrite if specified
If use the overloads with success callbacks if you need to know when the save has completed successfully
Arguments
bool | useOptimisticLock |
If true, the save will only be completed if the database object has not changed in BigDB since this instance was loaded. | |
bool | fullOverwrite |
Will completely overwrite the database object in BigDB with the properties in this instance, instead of just sending the changed properties to the server. |
DatabaseObject.Save
public void |
|
Persist the object to the database asynchronously.
If use the overloads with success callbacks if you need to know when the save has completed successfully
DatabaseObject.Save
public void |
|
Persist the object to the database, using optimistic locking and full overwrite if specified
Arguments
bool | useOptimisticLock |
If true, the save will only be completed if the database object has not changed in BigDB since this instance was loaded. | |
bool | fullOverwrite |
Will completely overwrite the database object in BigDB with the properties in this instance, instead of just sending the changed properties to the server. | |
Callback | successCallback |
Callback when the save succeeds |
DatabaseObject.Save
public void |
|
Persist the object to the database, using optimistic locking if specified
Arguments
bool | useOptimisticLock |
If true, the save will only be completed if the database object has not changed in BigDB since this instance was loaded. | |
Callback | successCallback |
Callback when the save succeeds |
DatabaseObject.Save
public void |
|
Persist the object to the database, using optimistic locking if specified
Arguments
bool | useOptimisticLock |
If true, the save will only be completed if the database object has not changed in BigDB since this instance was loaded. | |
Callback | successCallback |
Callback when the save succeeds | |
Callback<PlayerIOError> | errorCallback |
Callback that will be called instead of successCallback if an error occurs during the save. |
DatabaseObject.Save
public void |
|
Persist the object to the database, using optimistic locking and full overwrite if specified
Arguments
bool | useOptimisticLock |
If true, the save will only be completed if the database object has not changed in BigDB since this instance was loaded. | |
bool | fullOverwrite |
Will completely overwrite the database object in BigDB with the properties in this instance, instead of just sending the changed properties to the server. | |
Callback | successCallback |
Callback when the save succeeds | |
Callback<PlayerIOError> | errorCallback |
Callback that will be called instead of successCallback if an error occurs during the save. |
DatabaseObject.Set
public DatabaseObject |
|
Set the given property to the given object
Arguments
string | propertyExpression |
DatabaseObject | value |
DatabaseObject.Set
public DatabaseObject |
|
Set the given property to the given array
Arguments
string | propertyExpression |
DatabaseArray | value |
DatabaseObject.Set
public DatabaseObject |
|
Set the given property to the given string value
Arguments
string | propertyExpression |
string | value |
DatabaseObject.Set
public DatabaseObject |
|
Set the given property to the given datetime value
Arguments
string | propertyExpression |
DateTime | value |
DatabaseObject.Set
public DatabaseObject |
|
Set the given property to the given long value
Arguments
string | propertyExpression |
Int64 | value |
DatabaseObject.Set
public DatabaseObject |
|
Set the given property to the given uint value
Arguments
string | propertyExpression |
uint | value |
DatabaseObject.Set
public DatabaseObject |
|
Set the given property to the given int value
Arguments
string | propertyExpression |
int | value |
DatabaseObject.Set
public DatabaseObject |
|
Set the given property to the given bool value
Arguments
string | propertyExpression |
bool | value |
DatabaseObject.Set
public DatabaseObject |
|
Set the given property to the given byte array value
Arguments
string | propertyExpression |
Byte[] | value |
DatabaseObject.Set
public DatabaseObject |
|
Set the given property to the given double value
Arguments
string | propertyExpression |
Double | value |
DatabaseObject.Set
public DatabaseObject |
|
Set the given property to the given float value
Arguments
string | propertyExpression |
Single | value |