GORM Plugins/Setup
GrimmJSON Plugin (Local data management, good for local save systems)
- Configuration:
$GORM.Configure($GORM/GrimmJSON, {}, {
"ExampleCollection":{
"example_default_value":0,
}
})
SQLite Plugin
** Requires https://github.com/2shady4u/godot-sqlite- Configuration:
$GORM.Configure($GORM/SQLite, {}, {
"ExampleCollection":{
"example_default_value":0,
}
})
(WIP) PostgreSQL Plugin
(paused) MongoDBAtlas DataAPI Plugin (https://cloud.mongodb.com/)
** Disclaimer, you have to manage your collections via Atlas as the API restricts this action** Disclaimer, this plugin is a WIP and not done yet.
$GORM.Configure($GORM/MongoDBAtlas,
{
"api_key":"your_api_key",
"base_url":"your_base_url",
"data_source": "your_data_source",
"database": "your_database",
},
{
"ExampleCollection":{
"example_default_value":0,
}
})
Godot4.0 ORM CRUD Operations
To add new records to your collection, you can use the Create
operation.
Syntax:
$GORM.Create("CollectionName", {"field1": value1, "field2": value2})
Example:
$GORM.Create("Users", {"name": "John", "age": 30})
The Read
operation helps you to retrieve records based on certain conditions.
Syntax:
$GORM.Read("CollectionName", {"field__filter_type": value})
Example:
$GORM.Read("Users", {"name__icontains": "oh"})
The Update
operation allows you to modify existing records in your collection.
Syntax:
$GORM.Update("CollectionName", {"field1": new_value1}, {"field__filter_type": value})
Example:
$GORM.Update("Users", {"age": 31}, {"name__exact": "John"})
The Delete
operation helps you remove records from your collection.
Syntax:
$GORM.Delete("CollectionName", {"field__filter_type": value})
Example:
$GORM.Delete("Users", {"age__lt": 18})
The CreateCollection
operation allows you to create a new collection.
Syntax:
$GORM.CreateCollection("NewCollectionName")
Example:
$GORM.CreateCollection("Cars")
The DeleteCollection
operation allows you to delete an existing collection.
Syntax:
$GORM.DeleteCollection("CollectionName")
Example:
$GORM.DeleteCollection("Cars")
Godot4.0 ORM Filter Types
- Exact Match (
exact
) [default behavior
] - Case-Insensitive Exact Match (
iexact
) - Contains String (
contains
) - Case-Insensitive Contains String (
icontains
) - Greater Than (
gt
) - Greater Than or Equal To (
gte
) - Less Than (
lt
) - Less Than or Equal To (
lte
) - In List (
in
) - Within Range (
range
) - Is Null (
isnull
) - Regular Expression Match (
regex
) - Case-Insensitive Regular Expression Match (
iregex
) - Starts With (
startswith
) - Case-Insensitive Starts With (
istartswith
) - Ends With (
endswith
) - Case-Insensitive Ends With (
iendswith
)
Checks for an exact match.
Example:
$GORM.Read("ExampleCollection", {"name__exact": "John"})
Case-insensitive exact match.
Example:
$GORM.Read("ExampleCollection", {"name__iexact": "john"})
Checks if the field contains the given string.
Example:
$GORM.Read("ExampleCollection", {"name__contains": "oh"})
Case-insensitive containment check.
Example:
$GORM.Read("ExampleCollection", {"name__icontains": "oh"})
Greater than; works with numbers.
Example:
$GORM.Read("ExampleCollection", {"age__gt": 30})
Greater than or equal to; works with numbers.
Example:
$GORM.Read("ExampleCollection", {"age__gte": 30})
Less than; works with numbers.
Example:
$GORM.Read("ExampleCollection", {"age__lt": 30})
Less than or equal to; works with numbers.
Example:
$GORM.Read("ExampleCollection", {"age__lte": 30})
Checks if the field value is in the given list.
Example:
$GORM.Read("ExampleCollection", {"world_state__in": ["started", "ended", "ending"]})
Checks if the field value falls within a given range.
Example:
$GORM.Read("ExampleCollection", {"age__range": [30, 40]})
Checks if the field value is null or not.
Example:
$GORM.Read("ExampleCollection", {"email__isnull": true})
Checks if the field value matches the regular expression.
Example:
$GORM.Read("ExampleCollection", {"name__regex": "^Jo"})
Case-insensitive regular expression match.
Example:
$GORM.Read("ExampleCollection", {"name__iregex": "^jo"})
Checks if the field value starts with the given string.
Example:
$GORM.Read("ExampleCollection", {"name__startswith": "Jo"})
Case-insensitive check if the field value starts with the given string.
Example:
$GORM.Read("ExampleCollection", {"name__istartswith": "jo"})
Checks if the field value ends with the given string.
Example:
$GORM.Read("ExampleCollection", {"name__endswith": "n"})
Case-insensitive check if the field value ends with the given string.
Example:
$GORM.Read("ExampleCollection", {"name__iendswith": "N"})