Altruist UORM
Unified Object-Relational Mapping (UORM) system designed for seamless data management. It abstracts different persistance providers and offers a flexible, extensible approach for working with persistent data.
Database Providers
The framework supports multiple database providers under a common interface:
ILinqDatabaseProvider– Designed for Entity Framework Core and relational databases.ICqlDatabaseProvider– Optimized for Cassandra-based databases like ScyllaDB.
Note:
You don't need to interact with these providers directly unless you're implementing a custom provider.
ORM Model
Altruist provides its own ORM model to maintain consistency across different persistance providers.
Table Definition: TableAttribute
Defines a stored entity. It includes:
- Name: The entity name.
- StoreHistory: If
true, all updates are stored, useful for historical records like autosaves.
Note:
StoreHistory has no effect on caching
[Vault("game_state", StoreHistory = true)]
public class GameState {
}
Controlling Historical Storage
If a table is marked with StoreHistory = true, you can choose when to store data historically by passing an extra parameter when saving:
await vault.SaveAsync(gameState, storeHistory: true);
This allows fine-grained control over historical storage, preventing unnecessary data accumulation while still enabling selective snapshots.
Note:
Avoid enabling / saving history on frequently updated tables, as it can significantly increase unnecessary storage usage.
Primary Key: PrimaryKeyAttribute (Only DB)
Marks one or more properties as primary keys.
[PrimaryKey("Id")]
public class Player { }
Indexed Columns: ColumnIndexAttribute (Only DB)
Marks a property as indexed for faster lookups.
[ColumnIndex]
public int Level { get; set; }
Ignored Properties: IgnoreAttribute
Excludes a property from being stored in the database.
[Ignore]
public string TemporaryData { get; set; }
Sorting: SortingByAttribute (Only DB)
Automatically sorts queries by a specific column, useful for historical tables.
[SortingBy("SaveTime", Ascending: false)]
public class GameSave { }
Explicit Columns: ColumnAttribute
Explicitly marks a property as a table column. The name can be overridden.
[Column("player_name")]
public string Name { get; set; }
Vault System: Querying and Saving Data
Altruist provides a Vault System, which acts as an API for querying and managing database tables.
Keyspaces: Organizing Tables
A Keyspace is similar to a database schema. By default, the keyspace is altruist.
To define a custom keyspace:
public class MyScyllaKeyspace : ScyllaKeyspace
{
public override string Name { get; } = "mykeyspace";
}
Registering a Keyspace and Vault
During the database setup phase, register the keyspace and define which tables (vaults) belong to it.
.WithScyllaDB(setup => {
return setup
.AddContactPoint("localhost", 9042)
.CreateKeyspace<MyScyllaKeyspace>(setup =>
setup.ForgeVaults()
);
});
Using the Vault Repository
To interact with stored data, use IVaultRepository, which provides LINQ-like query capabilities.
IVaultRepository<MyScyllaKeyspace> vaultRepo;
Querying a Table (Vault)
var playerVault = vaultRepo.Select<Player>();
var players = await playerVault.Where(p => p.Level > 10).ToListAsync();
Note:
The Vault System only works with database providers (ILinqDatabaseProvider, ICqlDatabaseProvider) and does not support cache providers like Redis.