Home

Awesome

<h1 align="center"> <a>Gedaq</a> </h1> <h1 align="center"> <a href="https://discord.gg/xsR5EYU4ZM"><img height="30px" src="https://img.shields.io/badge/Discord-7289DA?style=for-the-badge&logo=discord&logoColor=white"><img></a> </h1> <h3 align="center">

Nuget Downloads Stars License

</h3>

Generator for obtaining and mapping data from the database. Generates methods (synchronous and/or asynchronous):

There are versions for all of these methods (if possible):

It also generates methods specific to each provider, such as BinaryImport and BinaryExport in PostgreSQL.

Supported databases(see examples and documentation in the relevant DB package):<br>

Usage:

For example, we have a Person class:


public class Person
{
    public int Id { get; set; }

    public string FirstName { get; set; }

    public string MiddleName { get; set; }

    public string LastName { get; set; }
    
    public Identification Identification { get; set; }
}

public class Identification
{
    public int Id { get; set; }
    public string TypeName { get; set; }
}

We just mark anywhere in the code with a special attribute (class, structure, method) that tells the analyzer to generate the code. Let's mark the Person class itself with an attribute:


[Query(
            @"
SELECT 
    p.id,
    p.firstname,
~StartInner::Identification:id~
    i.id,
    i.typename,
~EndInner::Identification~
    p.middlename,
    p.lastname
FROM person p
LEFT JOIN identification i ON i.id = p.identification_id
WHERE p.id > $1
",
        "GetAllPerson",
        typeof(Person),
        MethodType.Sync | MethodType.Async
        ),
        Parametr(parametrType: typeof(int), position: 1)
        ]
public class Person
//...

Now in the code we can call the ready method:


var persons = 
        connection
        .GetAllPerson(49999)
        .ToList();
        
var personsAsync = 
        await connection
        .GetAllPersonAsync(49999)
        .ToListAsync();

Comparison with Dapper and DapperAOT of getting 50000 Person in a loop(Size is number of loop iterations) from the database:

.NET 7 Benchmark:

MethodSizeMeanRatioAllocatedAlloc Ratio
Gedaq.Npgsql10445.5 ms1.00132.09 MB1.00
Dapper10749.2 ms1.68150.41 MB1.14
DapperAOT10777.5 ms1.75150.4 MB1.14
Gedaq.Npgsql20901.9 ms1.00264.17 MB1.00
Dapper201,510.0 ms1.68300.81 MB1.14
DapperAOT201,505.3 ms1.67300.81 MB1.14
Gedaq.Npgsql301,366.2 ms1.00396.28 MB1.00
Dapper302,276.7 ms1.67451.22 MB1.14
DapperAOT302,279.6 ms1.67451.22 MB1.14

But with Gedaq, we can prepare the command in advance.


var personsCmd = connection.CreateGetAllPersonCommand(prepare: true);
personsCmd.SetGetAllPersonParametrs(49999);
var persons = personsCmd.ExecuteGetAllPersonCommand().ToList();

//or

var personsCmd = await connection.CreateGetAllPersonCommandAsync(prepare: true);
personsCmd.SetGetAllPersonParametrs(49999);
var persons = await personsCmd.ExecuteGetAllPersonCommandAsync().ToListAsync();