Ultra fast multi threads/tasks .Net Database framework.
Norm
is stands for Not an ORM is a C#
lib for very HIGH Speed DB
data processing in async
way with immediately operations and at background with Processing data with Batches. It at least 10 times faster then EF/EF.Core
. In Comparison to ORMs Norm has following disadvantages:
But it gives us the following:
Table size (rows) | Rows to select | Time, ms |
---|---|---|
100k | 10k | 154 |
100k | 10k in a middle | 190 |
100k | 100k | 1114 |
1M | 100k | 1135 |
1M | 500k | 5624 |
i5
CPU for MySql 8.0.23
with default settings)Rows to insert | Time, ms |
---|---|
100 | 13 |
1000 | 62 |
10000 | 549 |
100000 | 5111 |
ORMs
BULK
operationsasync
behavior)CQRS
approach because works in own thread and uses multiple tasks.Create
, Update
and Delete
) are using DB Transactions
.Norm
works with persistant entities (table mapping or aggregate to multiple tables) via Repository
interface IDbRepository<T>
(T is a generic type of persistant object, i.e. User
). Norm
has following implementation of IDbRepository<T>
interface:
MySqlBufferedRepository<T>
for MySql
DB server, it implements BufferedDbRepository<T>
SqlServerBufferedRepository<T>
for SqlServer
DB server, it implements BufferedDbRepository<T>
SqLiteBufferedRepository<T>
for SqLite
DB server, it implements BufferedDbRepository<T>
Consider how to use it on MySql Db:
IDbRepository<T>
instance as follows:
DbRepositorySettings dbRepositorySettings = new DbRepositorySettings()
{
BufferThreshold = 100,
CommandTimeout = 120,
BufferSynchronizationDelayTimeout = 100,
ForceSynchronizationBufferDelay = 500
};
IDbRepository<PhysicalValueEntity> repo = new MySqlBufferedRepository<PhysicalValueEntity>(ConnectionString, dbRepositorySettings,
new PhysicalValueQueryBuilder(),
PhysicalValueFactory.Create, new NullLoggerFactory());
Contructor expect following params:
BufferThreshold
size of buffer (creainge or updainge entities) to syncTimeout
of executing command in secondsBufferSynchronizationDelayTimeout
time in ms between background synchronization iterations attemptsForceSynchronizationBufferDelay
timeout for sync if amount of items to create/update < BufferThresholdIDbEntityQueryBuilder<TE>
(see example in tests)IList<PhysicalValueEntity> items = await repo.GetManyAsync(page, size, new List<WhereParameter>(), null);
3.2 With filtering
IList<PhysicalValueEntity> items = await repo.GetManyAsync(page, size, new List<WhereParameter>()
{
new WhereParameter("id", null, false, WhereComparison.Greater, new List<object>(){lowerIdValue}, false),
new WhereParameter("id", WhereJoinCondition.And, false, WhereComparison.Less, new List<object>(){upperIdValue}, false)
}, null);
PhysicalValueEntity entity = new PhysicalValueEntity()
{
Id = id,
Name = "new phys value",
Description = "new phys value",
Designation = "NPV"
};
bool result = await repo.InsertAsync(entity, true);
The last insert method param is responsible for inserting into the Repository task in the background if false or immediately if true 4.2 Bulk
IList<PhysicalValueEntity> newPhysValues = new List<PhysicalValueEntity>()
{
new PhysicalValueEntity()
{
Id = 30,
Name = "new phys value",
Description = "new phys value",
Designation = "NPV"
},
new PhysicalValueEntity()
{
Id = 31,
Name = "new phys value2",
Description = "new phys value2",
Designation = "NPV2"
},
new PhysicalValueEntity()
{
Id = 32,
Name = "new phys value3",
Description = "new phys value3",
Designation = "NPV3"
}
};
int result = await repo.BulkInsertAsync(newPhysValues, true);
bool result = await repo.DeleteAsync(new List<WhereParameter>()
{
new WhereParameter("id", null, false, WhereComparison.Equal, new List<object>(){newPhysValue.Id})
});