Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pokkeyuri/simplesequel
SQL statements with minimal boilerplate code
https://github.com/pokkeyuri/simplesequel
ado-net csharp csharp-library database-library dotnet dotnet8 sql sql-library
Last synced: 2 months ago
JSON representation
SQL statements with minimal boilerplate code
- Host: GitHub
- URL: https://github.com/pokkeyuri/simplesequel
- Owner: PokkeYuri
- License: mit
- Created: 2024-02-11T00:00:10.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2024-03-03T19:30:43.000Z (11 months ago)
- Last Synced: 2024-10-13T14:21:59.641Z (3 months ago)
- Topics: ado-net, csharp, csharp-library, database-library, dotnet, dotnet8, sql, sql-library
- Language: C#
- Homepage:
- Size: 34.2 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
SimpleSequel is a lightweight .NET library designed to simplify interaction with databases. It provides intuitive extensions for executing SQL commands and queries and is built on top of ADO.NET.
This library requires .NET 8.
## Features
- Fetch and execute from the database with minimal boilerplate code.
- Execute SQL statements directly from string objects.
- Easily convert database rows into .NET objects or specific classes.
- Automatically handles the opening and closing of your database connection as necessary.## Usage
Before using SimpleSequel in your project, ensure you have a database that is compatible with ADO.NET, as the library utilizes `System.Data.Common.DbConnection` class from the ADO.NET framework for database connections. This step is essential for setting up the library to work seamlessly with your database management system (DBMS).
```csharp
using SimpleSequel;// Initialize SimpleSequel with your DBMS connection
SimpleSequelManager.Initialize(DbConnection.Connection);
```
Below are some examples of how to use SimpleSequel extensions in your .NET applications.
For more usage and examples please refer to the tests included in the 'SqlExtensionsTests' project within this repository.### Executing a SQL statement
```cs
// Execute a statement
"INSERT INTO KeyValueTable VALUES ( 'Gandalf', 'Wizard' )".ExecuteStatement();// Execute a statement async
await "INSERT INTO KeyValueTable VALUES ( 'Gandalf', 'Wizard' )".ExecuteStatementAsync();
```### Execute and getting a custom value
```cs
// Execute a command and get a scalar value
var value = "SELECT Value FROM KeyValueTable WHERE Key = 'Gandalf'".ExecuteScalar();// Execute a command asynchronously and get a scalar value
var valueAsync = await "SELECT Value FROM KeyValueTable WHERE Key = 'Gandalf'".ExecuteScalarAsync();
```### Executing for SQL query
```cs
// Execute a query and get a DbDataReader
DbDataReader reader = "SELECT * FROM KeyValueTable".ExecuteReader();// Execute a query asynchronously and get a DbDataReader
DbDataReader readerAsync = await "SELECT * FROM KeyValueTable".ExecuteReaderAsync();
```### Execute and getting an object from custom class
```cs
class KeyValue
{
public string Key { get; set; }
public string Value { get; set; }
}// Execute and get only first row as custom object
KeyValue keyValue = "SELECT * FROM KeyValueTable ORDER BY Key".ExecuteClass();
```## Todo's
- Add XML documentation comments
- Complete support for both synchronous and asynchronous operations
- Implement logging
- Complete CRUD operations for ORM
- Implement methods using DbParameters to prevent SQL Injections## License
This project is licensed under the MIT License. See the LICENSE file for more details.