FluentDbTools provides a fluent SQL abstraction layer for creating database connections, building sql queries and migrating your database.
Following databases are currently supported:
- Oracle
- Postgres
- FluentDbTools.Abstractions:
- FluentDbTools.Common.Abstractions:
- FluentDbTools.Migration.Abstractions:
- FluentDbTools.SqlBuilder.Abstractions:
- FluentDbTools.Contracts:
- FluentDbTools.Migration.Contracts:
- FluentDbTools.Extensions.DbProvider:
- FluentDbTools.Extensions.SqlBuilder:
- FluentDbTools.Extensions.Migration:
- FluentDbTools.Extension.MSDependencyInjection:
- FluentDbTools.Extension.MSDependencyInjection.Oracle:
- FluentDbTools.Extension.MSDependencyInjection.Postgres:
- FluentDbTools.DbProviders:
- FluentDbTools.Migration:
- FluentDbTools.Migration.Common:
- FluentDbTools.Migration.Oracle:
- FluentDbTools.Migration.Postgres:
- FluentDbTools.SqlBuilder:
- FluentDbTools.SqlBuilder.Dapper:
The IDbConfig interface is the only member you need to instantiate.
It provides a simple interface for providing which database type to use, and other necessary database settings.
IDbConfigdbConfig=newDbConfig(..)// Implementantion of IDbConfig requested
OracleClientFactory.Instance.Register(SupportedDatabaseTypes.Oracle);// Register the database factories you see fitNpgsqlFactory.Instance.Register(SupportedDatabaseTypes.Postgres);vardbConnection=dbConfig.CreateDbConnection();varserviceCollection=newServiceCollection();varserviceProvider=serviceCollection.AddSingleton<IConfiguration>(serviceProvider =>newConfigurationBuilder().AddJsonFile("config.json")).AddOracleDbProvider().AddPostgresDbProvider().BuildServiceProvider();using(varscope=serviceProvider.CreateScope()){vardbFactory=scope.ServiceProvider.GetService<DbProviderFactory>();vardbConnection=scope.ServiceProvider.GetService<IDbConnection>();}"database": {
"type": "postgres",
"user": "dbuser",
"password": "dbpassword",
"adminUser": "admindbuser",
"adminPassword": "admindbuser",
"schema": "dbuser", "databaseName": "dbuser", "hostname": "localhost",
"port": 5432,
"pooling": true,
// If you want all tables should be prefixed with EX // i.e. Person will give tablename EXPerson in the database"schemaPrefix": {
"Id": "EX", "UniqueId": "excv", "tables": {
// ChangeLogContext for table "Person""person": {
"GlobalId": "abcd",
"ShortName": "EXTST"
}
}
}
"migration": {
"schemaPassword": "dbpassword" }
}
// If database:schema not set, then it equals to 'database:user'// If database:databaseName not set, then it equals to 'database:schema'// If database:schemaPassword not set, then it equals to 'database:password'IDbConfigdbConfig=DbConfigDatabaseTargets.Create(databaseTypes,schema);varsql=dbConfig.CreateSqlBuilder().Select().OnSchema().Fields<Person>(x =>x.F(item =>item.Id)).Fields<Person>(x =>x.F(item =>item.SequenceNumber)).Fields<Person>(x =>x.F(item =>item.Username)).Fields<Person>(x =>x.F(item =>item.Password)).Where<Person>(x =>x.WP(item =>item.Id)).Build();IEnumerable<Assembly> migrationAssemblies =>new[]{typeof(AddPersonTable).Assembly};varserviceProvider=newServiceCollection().AddSingleton<IConfiguration>(serviceProvider =>newConfigurationBuilder().AddJsonFile("config.json")).ConfigureWithMigrationAndScanForVersionTable(migrationAssemblies).BuildServiceProvider();using(varscope=provider.CreateScope()){varmigrationRunner=scope.ServiceProvider.GetService<IMigrationRunner>();migrationRunner.MigrateUp();}[Migration(1,"Migration Example With SchemaPrefix")]publicclassAddPersonTable:MigrationModel{publicoverridevoidUp(){// Create the ChangeLogContext with values from this.GetMigrationConfig()// -// SchemaPrefixId is fetched from database:migration:schemaPrefix:id or database:schemaPrefix:id<br/>// SchemaPrefixUniqueId is fetched from database:migration:schemaPrefix:UniqueId or database:schemaPrefix:UniqueId<br/>// -// GlobalId is fetched from database:migration:schemaPrefix:tables:person:GlobalId or database:schemaPrefix:tables:person:GlobalId<br/>// ShortName is fetched from database:migration:schemaPrefix:tables:person:ShortName or database:schemaPrefix:tables:person:ShortName<br/>varpersonChangeLogContext=newChangeLogContext(this,Table.Person);// When "database:schemaPrefix:Id" or "database:migration:schemaPrefix:Id" have a value,// the tableName Person will be created as {SchemaPrefixId}Person.//// i.e: "database:schemaPrefix:Id" = "EX" => a table with name EXPerson will be created.// If both "database:schemaPrefix:Id" and "database:migration:schemaPrefix:Id" is missing,// a table with name Person will be created.Create.Table(Table.Person.GetPrefixedName(SchemaPrefixId)).InSchema(personChangeLogContext).WithChangeLog(PersonLogContext)// ChangeLog activation for Create.Table(..).WithColumn(Column.Id).AsGuid().PrimaryKey().WithColumn(Column.SequenceNumber).AsInt32().NotNullable().WithColumn(Column.Username).AsString().WithColumn(Column.Password).AsString().WithDefaultColumns()// Enable DefaultColumns functionality.WithTableSequence(this);}publicoverridevoidDown(){varpersonChangeLogContext=newChangeLogContext(this,Table.Person);Delete.Table(GetPrefixedName(Table.Person)).WithChangeLog(personChangeLogContext,this).InSchema(SchemaName);}}Please have a look in the example folder:
- Install Docker
- Install Python and pip
- Windows: https://matthewhorne.me/how-to-install-python-and-pip-on-windows-10/
- Ubuntu: Python is installed by default
- Install pip: sudo apt-get install python-pip
- Install python dependencies:
- pip install DockerBuildManagement
- See available commands:
dbm -help
- Start domain development by deploying service dependencies:
dbm -swarm -start
- Test solution in containers:
dbm -test
- Open solution and continue development:
- Publish new nuget version:
- Bump version in CHANGELOG.md
- Build and publish nugets:
dbm -build -run -publish
- Stop development when you feel like it:
dbm -swarm -stop