Beispiel #1
0
        public SQLiteEventStoreMigration(
            ILogger <SQLiteEventStoreMigration> logger,
            DbUpMigration.Factory factory,
            ISQLiteDbFactory sqLiteDbFactory,
            IStorageMigrationContainer storageMigrationContainer,
            IMasterOrSelfIdentity masterOrSelfIdentity,
            ISQLiteEventStoreOptions options)
        {
            var identity         = masterOrSelfIdentity.Identity;
            var storeLocator     = options.RelationalEventStoreLocator;
            var connectionName   = storeLocator.GetConnectionName(identity);
            var eventTableName   = storeLocator.GetEventTableName(identity);
            var migrationOptions = new DbUpMigrationOptions(
                new[] { Assembly.GetExecutingAssembly() },
                fileName => fileName.EndsWith("-event.sql"),
                new Dictionary <string, string>
            {
                { "EventTableName", eventTableName }
            },
                () =>
            {
                var dbConnection = sqLiteDbFactory.GetConnection(connectionName);
                var builder      = DeployChanges.To.SQLiteDatabase(new SharedConnection(dbConnection));
                return(builder, dbConnection);
            });
            var migration    = factory.Invoke(logger, migrationOptions);
            var migrationKey =
                $"{nameof(SQLiteEventStoreMigration)}_{connectionName}_{eventTableName}";

            _migrationTask = storageMigrationContainer.CreateTask(migrationKey, migration);
        }
        public async Task <StateEntity?> GetStateSnapshotAsync()
        {
            using var db = _sqLiteDbFactory.GetConnection(_connectionName);
            var ps   = new { ClaptrapTypeCode = _claptrapIdentity.TypeCode, ClaptrapId = _claptrapIdentity.Id };
            var item = await db.QueryFirstOrDefaultAsync <RelationalStateEntity>(_selectSql, ps);

            if (item == null)
            {
                return(null);
            }

            var re = new StateEntity
            {
                Version          = item.version,
                ClaptrapId       = item.claptrap_id,
                StateData        = item.state_data,
                UpdatedTime      = item.updated_time,
                ClaptrapTypeCode = item.claptrap_type_code
            };

            return(re);
        }
Beispiel #3
0
        public async Task <IEnumerable <EventEntity> > SelectAsync(long startVersion, long endVersion)
        {
            await using var db = _sqLiteDbFactory.GetConnection(_connectionName);
            var entities = await db.QueryAsync <RelationalEventEntity>(_selectSql, new
            {
                startVersion,
                endVersion,
                ClaptrapTypeCode = _masterOrSelfIdentity.TypeCode,
                ClaptrapId       = _masterOrSelfIdentity.Id
            });

            var re = entities.Select(x => new EventEntity
            {
                Version          = x.version,
                ClaptrapId       = x.claptrap_id,
                CreatedTime      = x.created_time,
                EventData        = x.event_data,
                ClaptrapTypeCode = x.claptrap_type_code,
                EventTypeCode    = x.event_type_code
            }).ToArray();

            return(re);
        }