![]() |
VOOZH | about |
dotnet add package DatabaseWrapper.Core --version 6.1.5
NuGet\Install-Package DatabaseWrapper.Core -Version 6.1.5
<PackageReference Include="DatabaseWrapper.Core" Version="6.1.5" />
<PackageVersion Include="DatabaseWrapper.Core" Version="6.1.5" />Directory.Packages.props
<PackageReference Include="DatabaseWrapper.Core" />Project file
paket add DatabaseWrapper.Core --version 6.1.5
#r "nuget: DatabaseWrapper.Core, 6.1.5"
#:package DatabaseWrapper.Core@6.1.5
#addin nuget:?package=DatabaseWrapper.Core&version=6.1.5Install as a Cake Addin
#tool nuget:?package=DatabaseWrapper.Core&version=6.1.5Install as a Cake Tool
| Library | Version | Downloads |
|---|---|---|
| DatabaseWrapper (all supported database types) | 👁 NuGet Version |
👁 NuGet |
| DatabaseWrapper.Mysql | 👁 NuGet Version |
👁 NuGet |
| DatabaseWrapper.Postgresql | 👁 NuGet Version |
👁 NuGet |
| DatabaseWrapper.Sqlite | 👁 NuGet Version |
👁 NuGet |
| DatabaseWrapper.SqlServer | 👁 NuGet Version |
👁 NuGet |
| DatabaseWrapper.Core | 👁 NuGet Version |
👁 NuGet |
| ExpressionTree | 👁 NuGet Version |
👁 NuGet |
DatabaseWrapper is the EASIEST and FASTEST way to get a data-driven application up and running using SQL Server, MySQL, PostgreSQL, or Sqlite.
For a sample app exercising this library, refer to the numerous Test projects contained within the solution.
Core features:
Special thanks to those who have helped contribute or otherwise improve the library!
@shawty @constantinje @thedarklort @l-404-l @igrgurina @Vaelek @treyhay31 @daoye @twobytescy @rinkusahu1 @Skimmenthal13
Use of parameterized queries vs building queries dynamically is a sensitive subject. Proponents of parameterized queries have data on their side - that parameterization does the right thing to prevent SQL injection and other issues. I do not disagree with them. However, it is worth noting that with proper care, you CAN build systems that allow you to dynamically build queries, and you SHOULD do so as long as you build in the appropriate safeguards.
If you find an injection attack that will defeat the sanitization layer built into this project, please let me know!
Refer to the test project for a more complete example with sample table setup scripts.
using DatabaseWrapper;
using DatabaseWrapper.Core;
using ExpressionTree;
DatabaseClient client = null;
// Sqlite
client = new DatabaseClient("[databasefilename]");
// SQL Server, MySQL, or PostgreSQL
client = new DatabaseClient(DbTypes.SqlServer, "[hostname]", [port], "[user]", "[password]", "[databasename]");
client = new DatabaseClient(DbTypes.Mysql, "[hostname]", [port], "[user]", "[password]", "[databasename]");
client = new DatabaseClient(DbTypes.Postgresql, "[hostname]", [port], "[user]", "[password]", "[databasename]");
// SQL Express
client = new DatabaseClient(DbTypes.SqlServer, "[hostname]", [port], "[user]", "[password]", "[instance]", "[databasename]");
// some variables we'll be using
Dictionary<string, object> d;
Expr e;
List<string> fields;
DataTable result;
// add a record
d = new Dictionary<string, object>();
d.Add("firstName", "Joel");
d.Add("lastName", "Christner");
d.Add("notes", "Author");
result = client.Insert("person", d);
result = await client.InsertAsync("person", d);
// update a record
d = new Dictionary<string, object>();
d.Add("notes", "The author :)");
e = new Expr("firstName", OperatorEnum.Equals, "Joel");
client.Update("person", d, e);
await client.UpdateAsync("person", d, e);
// retrieve 10 records
fields = new List<string> { "firstName", "lastName" }; // leave null for *
e = new Expr("lastName", OperatorEnum.Equals, "Christner");
ResultOrder[] order = new ResultOrder[1];
order = new ResultOrder("firstName", OrderDirectionEnum.Ascending)
result = client.Select("person", 0, 10, fields, e, order);
result = await client.SelectAsync("person", 0, 10, fields, e, order);
// delete a record
e = new Expr("firstName", Operators.Equals, "Joel");
client.Delete("person", e);
await client.DeleteAsync("person", e);
// execute a raw query
result = client.Query("SELECT customer_id FROM customer WHERE customer_id > 10");
result = await client.QueryAsync("SELECT customer_id FROM customer WHERE customer_id > 10");
Expressions, i.e. the Expr class from ExpressionTree, can be nested in either the Left or Right properties. Conversion from Expr to a WHERE clause uses recursion, so you have a good degree of flexibility in building your expressions in terms of depth.
Expr e = new Expr {
Left = new Expr("age", OperatorEnum.GreaterThan, 30),
Operator = Operators.And,
Right = new Expr("height", OperatorEnum.LessThan, 74)
};
Use IndexStart, MaxResults, and ResultOrder[] to retrieve paginated results. The query will retrieve maxResults records starting at row number indexStart using an ordering based on orderByClause. See the example in the DatabaseWrapperTest project.
IMPORTANT: When doing pagination with SQL Server, you MUST specify an ResultOrder[].
ResultOrder[] order = new ResultOrder[1];
order = new ResultOrder("firstName", OrderDirectionEnum.Ascending);
DataTable result = client.Select("person", 5, 10, null, e, order);
We added a simple static method for this which you can use when building expressions (or elsewhere). An object method exists as well.
string ts = client.Timestamp(DateTime.Now);
// 08/23/2016 05:34:32.4349034 PM
string tso = client.Timestamp(DateTime.Now);
// 2016-08-23 17:34:32.446913
When using database-specific classes DatabaseWrapper.Mysql, DatabaseWrapper.Postgresql, DatabaseWrapper.SqlServer, or DatabaseWrapper.Sqlite, the constructor is simplified from what is shown above.
For Sqlite:
DatabaseClient client = new DatabaseClient("[databasefilename]");
For SQL Server, MySQL, or PostgreSQL:
DatabaseClient client = new DatabaseClient(DbTypes.SqlServer, "[hostname]", [port], "[user]", "[password]", "[databasename]");
DatabaseClient client = new DatabaseClient(DbTypes.Mysql, "[hostname]", [port], "[user]", "[password]", "[databasename]");
DatabaseClient client = new DatabaseClient(DbTypes.Postgresql, "[hostname]", [port], "[user]", "[password]", "[databasename]");
For SQL Server Express:
DatabaseClient client = new DatabaseClient(DbTypes.SqlServer, "[hostname]", [port], "[user]", "[password]", "[instance]", "[databasename]");
IndexStart and MaxResults are supplied demands use of ResultOrder[].runtimes folder into your project output directory. This directory is automatically created when building for .NET Core. To get this folder, build the Test.Sqlite project and navigate to the bin/debug/netcoreapp* directory. Then copy the runtimes folder into the project output directory of your .NET Framework application.Refer to CHANGELOG.md.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 is compatible. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 is compatible. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 is compatible. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on DatabaseWrapper.Core:
| Package | Downloads |
|---|---|
|
DatabaseWrapper.Sqlite
Simple database wrapper for Sqlite written in C# supporting dynamic query building and nesting using expressions. Refer to other DatabaseWrapper packages for support for SQL Server, MySQL, and PostgreSQL. |
|
|
DatabaseWrapper.Mysql
Simple database wrapper for MySQL written in C# supporting dynamic query building and nesting using expressions. Refer to other DatabaseWrapper packages for support for SQL Server, Sqlite, and PostgreSQL. |
|
|
DatabaseWrapper.SqlServer
Simple database wrapper for SQL Server written in C# supporting dynamic query building and nesting using expressions. Refer to other DatabaseWrapper packages for support for MySQL, Sqlite, and PostgreSQL. |
|
|
DatabaseWrapper.Postgresql
Simple database wrapper for Postgresql written in C# supporting dynamic query building and nesting using expressions. Refer to other DatabaseWrapper packages for support for SQL Server, Sqlite, and MySQL. |
|
|
WatsonORM.Core
Do not install this package directly. Core classes and static methods supporting WatsonORM packages. |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 6.1.5 | 12,399 | 2/4/2025 |
| 6.1.4 | 1,265 | 1/23/2025 |
| 6.1.3 | 241 | 1/23/2025 |
| 6.1.2 | 225 | 1/23/2025 |
| 6.1.0 | 1,598 | 9/19/2024 |
| 6.0.6 | 7,700 | 10/4/2023 |
| 6.0.5 | 7,916 | 8/29/2023 |
| 6.0.4 | 7,019 | 7/11/2023 |
| 6.0.3 | 371 | 7/11/2023 |
| 6.0.2 | 1,624 | 7/11/2023 |
| 6.0.1 | 330 | 7/11/2023 |
| 6.0.0 | 343 | 7/11/2023 |
| 5.0.3 | 629 | 2/2/2023 |
| 5.0.2 | 5,940 | 2/2/2023 |
| 5.0.1 | 1,426 | 2/2/2023 |
| 5.0.0 | 7,271 | 10/25/2022 |
| 4.1.5 | 12,662 | 8/29/2022 |
| 4.1.3 | 7,140 | 6/21/2022 |
| 4.1.1 | 7,858 | 5/27/2022 |
| 4.1.0 | 636 | 5/27/2022 |
Oracle support (thank you @Skimmenthal13!), bugfixes, dependency updates.