|
1 | | -# TagBites Repository Template for .NET |
| 1 | +# TagBites.DB |
2 | 2 |
|
3 | | -Repository template for .NET projects and tools for initialization and update. |
| 3 | +[](https://www.nuget.org/packages/TagBites.DB/) |
| 4 | +[](https://github.com/TagBites/TagBites.DB/blob/master/LICENSE) |
| 5 | + |
| 6 | +TagBites.DB is a library that simplifies query execution in .NET applications. It efficiently manages database connections, executes queries, and handles transactions. The library supports multiple database providers, including PostgreSQL and SQLite. |
| 7 | + |
| 8 | +> This project is not recommended for general use as there are better solutions available. |
| 9 | +This library was specifically designed for a very complex ERP system where a single connection and transaction pass through multiple libraries and functions. |
| 10 | +It allows tracking the start and end of connections and transactions, and hooking into various events such as connection opened, connection closed, transaction beginning, transaction committed, and more. |
| 11 | + |
| 12 | +## Features |
| 13 | + |
| 14 | +- **Database Abstraction**: Provides a unified API for interacting with different database systems. |
| 15 | +- **Connection Management**: Efficiently manages database connections and transactions. |
| 16 | +- **Cursor Management** (PostgreSQL): Supports cursor-based data retrieval for large datasets. |
| 17 | +- **Extensible**: Easily extendable to support additional database providers. |
| 18 | + |
| 19 | +## Supported Database Providers |
| 20 | + |
| 21 | +- PostgreSQL (supports all API features) |
| 22 | +- SQLite |
| 23 | +- SqlServer |
| 24 | + |
| 25 | +## Installation |
| 26 | + |
| 27 | +You can install the TagBites.DB packages via NuGet: |
| 28 | +``` |
| 29 | +dotnet add package TagBites.DB |
| 30 | +dotnet add package TagBites.DB.Postgres |
| 31 | +dotnet add package TagBites.DB.Sqlite |
| 32 | +dotnet add package TagBites.DB.SqlServer |
| 33 | +``` |
| 34 | + |
| 35 | +## Usage |
| 36 | + |
| 37 | +- **Initialize the Database Provider** |
| 38 | +```csharp |
| 39 | +var provider = new PgSqlLinkProvider("your_connection_string"); |
| 40 | +``` |
| 41 | + |
| 42 | +- **Execute Queries** |
| 43 | +```csharp |
| 44 | +using (var link = provider.CreateLink()) |
| 45 | +{ |
| 46 | + var result = link.Execute(SELECT * FROM your_table"); |
| 47 | + |
| 48 | + foreach (var row in result) |
| 49 | + { |
| 50 | + // ... |
| 51 | + } |
| 52 | +} |
| 53 | +``` |
| 54 | + |
| 55 | +- **Execute Scalar** |
| 56 | +```csharp |
| 57 | +using (var link = provider.CreateLink()) |
| 58 | +{ |
| 59 | + var value = link.ExecuteScalar<int>("SELECT 1"); |
| 60 | +} |
| 61 | + |
| 62 | +``` |
| 63 | + |
| 64 | +- **Batch execute** |
| 65 | +```csharp |
| 66 | +using (var link = provider.CreateLink()) |
| 67 | +{ |
| 68 | + var results = link.BatchExecute("SELECT 1; SELECT 2, 3"); |
| 69 | + |
| 70 | + foreach (var result in results) |
| 71 | + foreach (var row in result) |
| 72 | + { |
| 73 | + // ... |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +``` |
| 78 | + |
| 79 | +- **Delay Batch Execute** |
| 80 | +```csharp |
| 81 | +using (var link = provider.CreateLink()) |
| 82 | +{ |
| 83 | + var r1 = link.DelayedBatchExecute("SELECT 1"); |
| 84 | + // ... |
| 85 | + var r2 = link.DelayedBatchExecute("SELECT 2"); |
| 86 | + // .. |
| 87 | +
|
| 88 | + // First call to Result executes all delay queries at once. |
| 89 | + foreach (var result in r1.Result) |
| 90 | + { |
| 91 | + // ... |
| 92 | + } |
| 93 | +} |
| 94 | + |
| 95 | +``` |
0 commit comments