DBAutomator 0.2.0
DBAutomator was renamed to Dapper.SqlWriter
See the version list below for details.
dotnet add package DBAutomator --version 0.2.0
NuGet\Install-Package DBAutomator -Version 0.2.0
<PackageReference Include="DBAutomator" Version="0.2.0" />
paket add DBAutomator --version 0.2.0
#r "nuget: DBAutomator, 0.2.0"
// Install DBAutomator as a Cake Addin #addin nuget:?package=DBAutomator&version=0.2.0 // Install DBAutomator as a Cake Tool #tool nuget:?package=DBAutomator&version=0.2.0
devhl.DBAutomator
This .NET Standard 2.1 library allows you to easily save and retrieve your objects from a database.
Test Program
Begin by instantiating a QueryOptions object, and pass that into the DBAutomator class. Then register your database POCO classes with the library.
QueryOptions queryOptions = new QueryOptions
{
DataStore = DataStore.PostgreSQL,
};
queryOptions.ConnectionString = $"Server=127.0.0.1;Port=5432;Database=AutomatorTest;User ID=postgres;Password={password};";
DBAutomator postgres = new DBAutomator(queryOptions, logService);
postgres.Register(new UserModel());
postgres.Register(new AddressModel());
postgres.Register(new UserAddressModel());
Now you can save and retrieve your objects using Linq.
//delete all rows in the table
var a = await postgres.DeleteAsync<UserModel>();
//insert a new row
var b = await postgres.InsertAsync(newUser1);
//update an existing row
newUser1.UserName = "changed";
var h = await postgres.UpdateAsync(newUser1);
//update all matching rows
var i = await postgres.UpdateAsync<UserModel>(u => u.UserName == "changed again", u => u.UserName == "changed");
//get the required rows
var j = await postgres.GetAsync<UserModel>(u => u.UserID > 2);
var n = await postgres.GetAsync<UserModel>(u => u.UserID == 2);
var o = await postgres.GetAsync<UserModel>(u => u.UserID == 2 || u.UserName == "changed again");
var p = await postgres.GetAsync(u => u.UserID == 2 || u.UserName == "changed again", orderBy);
Configuring Your Classes
The Register method returns a RegisteredClass object. You may edit the TableName and ColumnName properties to point your class to the property database object. You may also decorate your class with attributes. This library uses five attributes from Entity Framework: Key, NotMapped, Table, Column, and DatabaseGenerated. The option you provide to the DatabaseGenereated is not relevant. The library will also work with views so you can easily get joins working.
IDBObject
Your classes can optionally implement the IDBObject interface. This will add call backs in your POCO when the library inserts, updates, deletes, or selects your object.
Compatibility
This library is tested with PostgreSQL but it may work with other databases as well. The table definitions used while testing can be found in the UserModel, AddressModel, and UserAddressModel files. The generated SQL is printed to the ILogger.Trace method.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Dapper (>= 2.0.4)
- EntityFramework (>= 6.3.0)
- Microsoft.Extensions.Logging.Abstractions (>= 3.0.0)
- Npgsql (>= 4.1.0-preview2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.