SqlSrcGen is a SQL first, reflection free micro ORM for SQLite using c# source generators. The class definitions and Object Relational Mappings are created automatically from your SQL CREATE TABLE commands.
- No need to manually define c# classes for your tables
- High performance - mapping code is reflection free and optimized at compile time
- SQL code is compile time checked
- AOT friendly - no reflection
- Create a .sql file in your project which includes the CREATE TABLE SQL commands defining your database.
CREATE TABLE contact (name Text not null primary key, email Text not null);
- Include that .sql file as AdditionalFiles in your .csproj
<ItemGroup>
<AdditionalFiles Include="SqlSchema.sql" />
</ItemGroup>
- Do crud operations on the tables
var database = new Database(databaseName);
// create the table
database.CreateContactTable();
// insert a record
database.InsertContact(new Contact()
{
Name = "Steve Rogers",
Email = "steve@avengers.com"
});
// query all records in the table
var list = new List<Contact>();
database.AllContacts(list);
// get row via primary key, (only generated for tables with a primary key)
var contact = new Contact();
bool found = database.GetContact(contact, "Steve Rogers");
// delete all rows from table
database.DeleteAllContacts();
// delete a row via primary key (only generated for tables with a primary key)
database.DeleteContact("Steve Rogers");
// Begin a transaction
database.BeginTransaction();
// Commit a transaction
database.CommitTransaction();
// Rollback a transaction
database.RollbackTransaction();
SqlSrcGen currently only supports basic crud operations generated directly from sql table definitions. Future features include:
- Custom queries (select, joins etc)