Esempio n. 1
0
        private static void InitializeRepoDb()
        {
            var provider = MixService.GetEnumConfig <MixDatabaseProvider>(MixConstants.CONST_SETTING_DATABASE_PROVIDER);

            switch (provider)
            {
            case MixDatabaseProvider.MSSQL:
                SqlServerBootstrap.Initialize();
                break;

            case MixDatabaseProvider.MySQL:
                MySqlBootstrap.Initialize();
                break;

            case MixDatabaseProvider.PostgreSQL:
                PostgreSqlBootstrap.Initialize();
                break;

            case MixDatabaseProvider.SQLITE:
                SqLiteBootstrap.Initialize();
                break;

            default:
                SqLiteBootstrap.Initialize();
                break;
            }
        }
Esempio n. 2
0
        public static void Initialize()
        {
            // Initialize SqLite
            SqLiteBootstrap.Initialize();

            // Check the type of database
            if (IsInMemory == true)
            {
                // Memory
                ConnectionStringSDS = @"Data Source=:memory:;";
                ConnectionStringMDS = @"Data Source=:memory:;";
            }
            else
            {
                // Local
                ConnectionStringSDS = @"Data Source=C:\SqLite\Databases\RepoDb.db;Version=3;";

                // Local
                ConnectionStringMDS = @"Data Source=C:\SqLite\Databases\RepoDb.db;";

                // Create tables
                CreateSdsTables();
                CreateMdsTables();
            }
        }
 /// <summary>
 /// Called when [post startup].
 /// </summary>
 public override void OnPostStartup()
 {
     // Initialize ORM
     SqLiteBootstrap.Initialize();
     // Doesn't work as well with MDS which I prefer to use... Reported to the authors who said it should be turned on if you use MDS.
     Converter.ConversionType = RepoDb.Enumerations.ConversionType.Automatic;
 }
Esempio n. 4
0
        private static void Main(string[] args)
        {
            _connectionString = $"Data Source = {DbFileName}";
            SqLiteBootstrap.Initialize();
            ITeacherRepository teacherRepository = new TeacherRepository(_connectionString);
            IStudentRepository studentRepository = new StudentRepository(_connectionString);
            var controller = new StudentController(studentRepository, teacherRepository);
            var exists     = File.Exists(DbFileName);

            if (!exists)
            {
                CreateTestDatabase();
                var generate = controller.Generate();
                Console.WriteLine($"Generated {generate.Inserted:N0} students in {generate.ElapsedInMilliseconds:N1} msec");
            }
            var queryStat = controller.GetQueryStat();

            Console.WriteLine($"QueryStat: {queryStat.Iteration:N0} students in {queryStat.ElapsedInMilliseconds:N1} msec");
            var queryStatCache = controller.GetQueryStatCache();

            Console.WriteLine($"QueryStat: {queryStatCache.Iteration:N0} students in {queryStatCache.ElapsedInMilliseconds:N1} msec");

            var subset = teacherRepository.GetTeachersWithStudents(new List <int> {
                2, 3, 4
            }).ToList();

            Debug.Assert(subset.Count == 3);
            var students0 = subset[0].Students.ToList();

            Debug.Assert(students0.Count > 0);
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
Esempio n. 5
0
        public async Task TestGetWithBusinessLayer()
        {
            await CreateOrdersDb();

            SqLiteBootstrap.Initialize();

            await using var connection = new SQLiteConnection(OrdersDbContext.ConnectionString);
            var repoDbDataLayer = new RepoDbDataLayer(connection);

            var businessLayer = new BusinessLayer(
                whereAsync: repoDbDataLayer.WhereAsync,
                beforeGet: (t, e) =>
            {
                _customBefore = true;
                return(Task.FromResult(true));
            },
                afterGet: (t, result) =>
            {
                _customAfter = true;
                return(Task.FromResult(true));
            });

            WhereAsync whereAsync = businessLayer.WhereAsync;

            var asyncEnumerable = await whereAsync
                                  .GetAsync <OrderRecord>(o => o.Id == _id);


            var returnValue = await asyncEnumerable.ToListAsync();

            Assert.AreEqual(1, returnValue.Count);
            Assert.IsTrue(_customBefore && _customAfter);
        }
Esempio n. 6
0
        public async Task TestGetRepoDb()
        {
            await CreateOrdersDb();

            SqLiteBootstrap.Initialize();

            await using var connection = new SQLiteConnection(OrdersDbContext.ConnectionString);
            var repoDbDataLayer = new RepoDbDataLayer(connection);
            var asyncEnumerable = await repoDbDataLayer.WhereAsync((Expression <Func <OrderRecord, bool> >) _getOrderByIdPredicate);


            var returnValue = await asyncEnumerable.ToListAsync();

            Assert.AreEqual(1, returnValue.Count);
        }
Esempio n. 7
0
        private void Form1_Load(object sender, EventArgs e)
        {
            SqLiteBootstrap.Initialize();

            builder.DataSource     = "./sample.db";
            builder.BusyTimeout    = 5000;
            builder.DateTimeFormat = SQLiteDateFormats.InvariantCulture;
            builder.DateTimeKind   = DateTimeKind.Local;
            builder.JournalMode    = SQLiteJournalModeEnum.Wal;
            builder.SyncMode       = SynchronizationModes.Off;
            builder.CacheSize      = 4000;
            builder.Add("cache", "shared");

            string connStr = builder.ConnectionString;

            conn = new SQLiteConnection(connStr);
            conn.Open();

            RefreshGrid();
        }
 public void Initialize()
 {
     SqLiteBootstrap.Initialize();
 }
Esempio n. 9
0
        static async Task Main(string[] args)
        {
            var txnFile = Path.Combine(DataDirectory, "txnlog.dat");
            var sqlFile = Path.Combine(DataDirectory, "mydb.sqlite");

            try
            {
                SqLiteBootstrap.Initialize();
                await using var fs = new FileStream(txnFile, FileMode.Open);
                var header = await fs.ReadMps7HeaderAsync();

                //await using var conn = new SQLiteConnection("Data Source=:memory:;Version=3;New=True;");
                await using var conn = new SQLiteConnection($"Data Source={sqlFile};Version=3;");
                var createTable = await conn.ExecuteNonQueryAsync(@"
                CREATE TABLE IF NOT EXISTS [Mps7Record]
                (                
	                Id INTEGER PRIMARY KEY AUTOINCREMENT,
	                TransactionCode INTEGER,
	                UnixTimeStamp INTEGER,
	                UserID INTEGER,
	                Amount NUMERIC
	            );"    );

                int transactionType;
                while ((transactionType = fs.ReadByte()) != -1)
                {
                    var mpsRecord = new Mps7Record
                    {
                        TransactionCode = (byte)transactionType,
                    };
                    var userAndTime = new byte[12];
                    fs.Read(userAndTime);
                    mpsRecord.UnixTimeStamp = (uint)userAndTime[Range.EndAt(4)].ToUInt64();
                    mpsRecord.UserId        = userAndTime[Range.StartAt(4)].ToUInt64();
                    if (mpsRecord.TransactionCode == 0x0 || mpsRecord.TransactionCode == 0x01)
                    {
                        var amount = new byte[8];
                        fs.Read(amount);
                        var y = BitConverter.IsLittleEndian;
                        mpsRecord.Amount = BitConverter.ToDouble((BitConverter.IsLittleEndian ?amount.Reverse() : amount).ToArray());
                    }
                    await conn.InsertAsync(mpsRecord);
                }

                var total = (await conn.ExecuteQueryAsync(@"
                        SELECT SUM
	                    (
	                    CASE TransactionCode
		                    WHEN 0 then Amount
		                    WHEN 1 then - Amount
		                    ELSE 0
		                    END
	                    ) as Total
                    FROM Mps7Record
                    WHERE UserId = @userId", new
                {
                    userId = 4596061716608039     //4596061716608039//2456938384156277127
                })).Select(z => z as IDictionary <string, object>).FirstOrDefault().FirstOrDefault(v => v.Key == "Total").Value;

                if (total != null)
                {
                    Console.WriteLine($"{Convert.ToDouble(total)}");
                }
                //ConsoleTable.From(display).Configure(o => o.NumberAlignment = Alignment.Right).Write(Format.Alternative);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
            Console.WriteLine($"balance for user 2456938384156277127=0.00");
        }