Activout.DatabaseClient
1.0.0
See the version list below for details.
dotnet add package Activout.DatabaseClient --version 1.0.0
NuGet\Install-Package Activout.DatabaseClient -Version 1.0.0
<PackageReference Include="Activout.DatabaseClient" Version="1.0.0" />
<PackageVersion Include="Activout.DatabaseClient" Version="1.0.0" />
<PackageReference Include="Activout.DatabaseClient" />
paket add Activout.DatabaseClient --version 1.0.0
#r "nuget: Activout.DatabaseClient, 1.0.0"
#addin nuget:?package=Activout.DatabaseClient&version=1.0.0
#tool nuget:?package=Activout.DatabaseClient&version=1.0.0
Activout Database Client
Create a database client only by defining the C# interface you want. Uses Dapper for object mapping.
Create a Database Access Object (DAO) defining the C# interface you want and writing the SQL query. Shamelessly inspired by Jdbi Declarative API.
Rationale
The Activout Database Client provides a type-safe approach to make SQL requests to the database.
For the actual object mapping, Dapper is used but another implementation can be configured.
Example
Synchronous
public interface IUserDao
{
[SqlUpdate("CREATE TABLE user (id INTEGER PRIMARY KEY, name VARCHAR)")]
void CreateTable();
[SqlUpdate("INSERT INTO user(id, name) VALUES (:id, :name)")]
void InsertNamed([Bind("id")] int id, [Bind("name")] string name);
[SqlUpdate("INSERT INTO user(id, name) VALUES (:id, :Name)")]
void InsertObject([BindProperties] User user);
[SqlUpdate("INSERT INTO user(id, name) VALUES (:user_id, :user_Name)")]
void InsertObjectFull([BindProperties] User user);
[SqlQuery("SELECT * FROM user ORDER BY name")]
IEnumerable<User> ListUsers();
[SqlQuery("SELECT * FROM user WHERE id = :id")]
User GetUserById(int id);
}
_userDao = new DatabaseClientBuilder()
.With(new DapperDatabaseConnection(sqliteConnection))
.With(new DapperGateway())
.Build<IUserDao>();
_userDao.CreateTable();
_userDao.InsertNamed(42, "foobar");
var user = _userDao.GetUserById(42);
Asynchronous
public interface IUserDaoAsync
{
[SqlUpdate("CREATE TABLE user (id INTEGER PRIMARY KEY, name VARCHAR)")]
Task CreateTable();
[SqlUpdate("INSERT INTO user(id, name) VALUES (:id, :name)")]
Task InsertNamed([Bind("id")] int id, [Bind("name")] string name);
[SqlUpdate("INSERT INTO user(id, name) VALUES (:id, :Name)")]
Task InsertObject([BindProperties] User user);
[SqlUpdate("INSERT INTO user(id, name) VALUES (:user_id, :user_Name)")]
Task InsertObjectFull([BindProperties] User user);
[SqlQuery("SELECT * FROM user ORDER BY name")]
Task<IEnumerable<User>> ListUsers();
[SqlQuery("SELECT * FROM user WHERE id = :id")]
Task<User> GetUserById(int id);
}
_userDao = new DatabaseClientBuilder()
.With(new DapperDatabaseConnection(sqliteConnection))
.With(new DapperGateway())
.Build<IUserDaoAsync>();
await _userDao.CreateTable();
await _userDao.InsertNamed(42, null);
var user = await _userDao.GetUserById(42);
Public projects using Activout.DatabaseClient
- Your project here?
TODO
- Positional parameters, if anyone cares?
- Make it configurable whether
:
or@
is used to mark named parameters - More real-life testing 😃
Collaborate
This project is still under development - participation welcome!
About Activout
Activout AB is a software company in Ronneby, Sweden.
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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp2.1 is compatible. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
-
.NETCoreApp 2.1
- ImpromptuInterface (>= 7.0.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Activout.DatabaseClient:
Package | Downloads |
---|---|
Activout.DatabaseClient.Dapper
Dapper Backend for Activout.DatabaseClient. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
5.0.0-rc1 | 218 | 3/4/2025 |
4.0.0 | 155 | 1/11/2025 |
3.0.0-beta | 414 | 10/17/2020 |
1.0.1 | 1,543 | 12/2/2018 |
1.0.0 | 1,202 | 12/2/2018 |