Beispiel #1
0
        public void TestSimpleRangeAboveQuery()
        {
            var dbTable = DbTable.CreateByRequest("myTable", false);

            for (var i = 0; i <= 100; i++)
            {
                var key            = (i * 2).ToString("000");
                var recordToInsert = new TestRecord
                {
                    PartitionKey = "MyPartition",
                    RowKey       = key,
                    TestField    = key
                };

                var recordIsByteArray = recordToInsert.AsJsonByteArray().AsMyMemory();

                var entity = recordIsByteArray.ParseDynamicEntity();

                dbTable.Insert(entity, DateTime.UtcNow);
            }

            var query = "PartitionKey eq 'MyPartition' and RowKey ge '199'";

            var queryCondition = query.ParseQueryConditions();

            var foundRecords = dbTable.ApplyQuery(queryCondition).ToArray();

            Assert.AreEqual(1, foundRecords.Length);

            Assert.AreEqual("200", foundRecords[0].GetValue("TestField"));
        }
Beispiel #2
0
        public void TestSimpleQuery()
        {
            var dbTable = DbTable.CreateByRequest("myTable", false);

            var recordToInsert = new TestRecord
            {
                PartitionKey = "MyPartition",
                RowKey       = "MyRow",
                TestField    = "Test"
            };

            var recordIsByteArray = recordToInsert.AsJsonByteArray();

            var fields = recordIsByteArray.AsMyMemory().ParseDynamicEntity();

            dbTable.Insert(fields, DateTime.UtcNow);

            var query = "PartitionKey eq 'MyPartition' and RowKey eq 'MyRow'";

            var queryCondition = query.ParseQueryConditions();

            var foundItems = dbTable.ApplyQuery(queryCondition).ToArray();

            Assert.AreEqual(recordToInsert.TestField, foundItems.First().GetValue("TestField"));
        }
Beispiel #3
0
        public void TestSimpleRangeAboveQuery()
        {
            var dbTable = DbTable.CreateByRequest("myTable");

            for (var i = 0; i <= 100; i++)
            {
                var key            = (i * 2).ToString("000");
                var recordToInsert = new TestRecord
                {
                    PartitionKey = "MyPartition",
                    RowKey       = key,
                    TestField    = key
                };

                var recordIsByteArray = recordToInsert.AsJsonByteArray().AsMyMemory();

                var fields = recordIsByteArray.ParseFirstLevelOfJson();

                dbTable.Insert(fields.GetEntityInfo(), fields);
            }

            var query = "PartitionKey eq 'MyPartition' and RowKey ge '199'";

            var queryCondition = query.ParseQueryConditions();

            var foundRecords = dbTable.ApplyQuery(queryCondition).ToArray();

            Assert.Single(foundRecords);

            Assert.Equal("200", foundRecords[0].GetValue("TestField"));
        }
Beispiel #4
0
        public void TestSimpleQuery()
        {
            var dbTable = DbTable.CreateByRequest("myTable");

            var recordToInsert = new TestRecord
            {
                PartitionKey = "MyPartition",
                RowKey       = "MyRow",
                TestField    = "Test"
            };

            var recordIsByteArray = recordToInsert.AsJsonByteArray();

            var fields = recordIsByteArray.AsMyMemory().ParseFirstLevelOfJson();

            var entityInfo = fields.GetEntityInfo();

            dbTable.Insert(entityInfo, fields);

            var query = "PartitionKey eq 'MyPartition' and RowKey eq 'MyRow'";

            var queryCondition = query.ParseQueryConditions();

            var foundItems = dbTable.ApplyQuery(queryCondition).ToArray();

            Assert.Equal(recordToInsert.TestField, foundItems.First().GetValue("TestField"));
        }
Beispiel #5
0
        private (DbTable table, bool createdNow) TryToCreateNewTable(string tableName, bool persistTable)
        {
            DbTable syncCreateTable = null;

            try
            {
                lock (_lockObject)
                {
                    if (_tables.TryGetValue(tableName, out var result))
                    {
                        if (result.Persist != persistTable)
                        {
                            result.UpdatePersist(persistTable);
                            syncCreateTable = result;
                        }
                        return(result, false);
                    }



                    var tableInstance = DbTable.CreateByRequest(tableName, persistTable);

                    var tables = new Dictionary <string, DbTable>(_tables)
                    {
                        { tableInstance.Name, tableInstance }
                    };

                    _tables = tables;

                    _tablesAsArray = _tables.Values.ToList();

                    syncCreateTable = tableInstance;

                    return(tableInstance, true);
                }
            }
            finally
            {
                if (syncCreateTable != null)
                {
                    _snapshotSaverScheduler.SynchronizeSetTablePersist(syncCreateTable, persistTable);
                }
            }
        }
Beispiel #6
0
        public static bool CreateTable(string tableName)
        {
            tableName = tableName.ToLowerInvariant();
            ReaderWriterLockSlim.EnterWriteLock();
            try
            {
                if (Tables.ContainsKey(tableName))
                {
                    return(false);
                }

                var tableInstance = DbTable.CreateByRequest(tableName);

                Tables.Add(tableName, tableInstance);

                return(true);
            }
            finally
            {
                ReaderWriterLockSlim.ExitWriteLock();
            }
        }