NugSQL 0.1.4
dotnet add package NugSQL --version 0.1.4
NuGet\Install-Package NugSQL -Version 0.1.4
<PackageReference Include="NugSQL" Version="0.1.4" />
paket add NugSQL --version 0.1.4
#r "nuget: NugSQL, 0.1.4"
// Install NugSQL as a Cake Addin #addin nuget:?package=NugSQL&version=0.1.4 // Install NugSQL as a Cake Tool #tool nuget:?package=NugSQL&version=0.1.4
NugSql
What is NugSql?
Nugql is descendant of HugSql, PugSql and PetaPoco. The main idea is that:
SQL is the right tool for the job when working with a relational database!
So, learning SQL should be enough for a programmer to start working with a RDBMS.
NugSql based on some unbreakable rules:
- No SQL generation!
All SQL queries should execute as they are written.
- No explicit mapping for standard parameters.
All DBMS basic data types (depend on DBMS) should be mapped automatically.
- No explicit mapping for standard results!
If result is a basic C# type or an object with properties of basic C# types, all mappings should be done automatically.
The first rule is the key, what makes NugSql fast, compatible and maintainable.
- No sql parsing is needed, so it is Fast.
- The same query you run inside your database tool will be used in app. So it is Compatible and Maintainable.
- The only parameters that effect your queries is your RDBMS! not the NugSql version, not anything else! so it is Maintainable.
The 2 last rules are the motivations to use an ORM!
Usage:
1. write your queries:
create user query:
-- :name create_user :scalar
insert into test.user(user_name, password, salt, profile, status)
values(:user_name, :password, :salt, :profile, :status) RETURNING id
get user list query:
-- :name get_users :many
select *
from test.user u
where u.user_name like :name
Attention: The first line is a SQL-comment that specify which method should be linked to this query and what kind of result we expect from this query.
2. define your entities:
public class User
{
public int id { get; set; }
public string user_name { get; set; }
public string profile { get; set; }
public byte[] salt { get; set; }
public byte[] password { get; set; }
public short status { get; set; }
}
3. define your database interface:
public interface IMyDB: IQueries
{
int create_user(string user_name, byte[] password, byte[] salt, Jsonb profile, short status);
IEnumerable<User> get_users(string name);
}
4. compile queries: (Singleton)
From external files:
var MyDBCompiledQuery = QueryBuilder.Compile<IMyDB>("path/to/queries", new PgDatabaseProvider());
Or from embedded resources:
var assembly = Assembly.GetAssembly(typeof(IMyDB));
var MyDBCompiledQuery = QueryBuilder.Compile<IMyDB>(assembly, new PgDatabaseProvider());
5. connect to database and use it: (Transient or Scoped)
var MyDB = QueryBuilder.New<IMyDB>(cnn, MyDBCompiledQuery);
using(var tr = MyDB.BeginTransaction())
{
MyDB.create_user("u1", new byte[0], new byte[0], @"{ ""title"":""test1"" }", 1);
MyDB.create_user("u2", new byte[0], new byte[0], @"{ ""title"":""test2"" }", 1);
tr.Commit();
}
foreach(var u in MyDB.get_users("u%"))
{
// Do something!
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. 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. |
-
net6.0
- System.Reflection.Emit (>= 4.7.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.1.4 | 765 | 11/14/2022 |