Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/trampster/SqlSrcGen
SqlSrcGen
https://github.com/trampster/SqlSrcGen
Last synced: 7 days ago
JSON representation
SqlSrcGen
- Host: GitHub
- URL: https://github.com/trampster/SqlSrcGen
- Owner: trampster
- License: mit
- Created: 2023-05-04T09:26:00.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-09-26T09:23:08.000Z (about 1 year ago)
- Last Synced: 2024-08-02T16:43:40.829Z (3 months ago)
- Language: C#
- Size: 357 KB
- Stars: 10
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# ![Logo](https://raw.githubusercontent.com/trampster/SqlSrcGen/main/Icon/SqlSrcGen64.png) SqlSrcGen
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.## Advantages
* 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## Getting Started
1. Create a .sql file in your project which includes the CREATE TABLE SQL commands defining your database.
```sql
CREATE TABLE contact (name Text not null primary key, email Text not null);
```2. Include that .sql file as AdditionalFiles in your .csproj
```xml
```
3. Do crud operations on the tables```c#
var database = new Database(databaseName);// create the table
database.CreateContactTable();// insert a record
database.InsertContact(new Contact()
{
Name = "Steve Rogers",
Email = "[email protected]"
});// query all records in the table
var list = new List();
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();
```## Future Work
SqlSrcGen currently only supports basic crud operations generated directly from sql table definitions. Future features include:
* Custom queries (select, joins etc)