CursiveDB - An ADO.NET wrapper
Features
CursiveDB is an ADO.NET wrapper library which encourages a fluent-style of programming. Apart from having a number of shortcut methods for creating and executing raw SQL queries and stored procedures, it's also got built-in support for retries, a light-weight Database to Object mapper and also a SQL script runner.
Almost all CursiveDB methods are implemented as extension methods of the ADO.NET Connection and Command classes. This ensures that CursiveDB does not get in the way of using standard ADO.NET classes.
In-built support for retriesAutomatic retries of failed database connections. You can use retries using the retry callbacks which are available while opening a database connection.
SqlConnection c = new SqlConnection(); int retryCount = 0; try { c .WithRetry() .MaximumTimes(3) .WithWaitOf(2000) .If((e, source) => { if (e is InvalidOperationException) return false; // stop retrying else return true; // do a retry }) .OpenConnection(); } catch(Exception ex) { Console.WriteLine("None of the retries succeeded! This is the final exception!"); }Retries for failed database commands
You can specify retry callbacks which are executed when data base command fails. These handlers are available in all most all methods which interact with a database.
SqlCommand cmd = new SqlCommand("select * from authors"); cmd .Retry() .MaximumTimes(3) /* retry 3 times */ .WithWaitOf(1000) /* wait for 1 sec between retries */ .ExecuteScalarFluent style ADO.NET productivity methods.();
CursiveDB methods make programming ADO.NET very simple. Methods are easy to use and provided via extension methods so you don't need to use any 'new' classes to enjoy the benefits of CursiveDB.
using (SqlConnection conn = GetConnection()) { using (SqlCommand cmd = conn.OpenConnection().QuerySimple light-weight ORM support("update Author Set Name = @newName where Name = @oldName")) { cmd .AppendInputParam("@newName", "foo") .AppendInputParam("@oldName", "bar"); .ExecuteNonQuery((affectedRowCount, source) => { Console.WriteLine("{0} rows affected", affectedRowCount); }); } }
In-built light-weight ORM support allows you to return class instances instead of Datasets or Data readers. Note, the support is very basic, if ORM is what you are after CursiveDB may not the library for you.
using (SqlConnection conn = new SqlConnection(connStr)) { conn.Open(); IListA SQL script runnerauthors = conn.Query("select * from Author").ResultSet (); foreach(Author a in authors) { Console.WriteLine(a.Name); } }
Just bundle up all your SQL statements like statements to create the schema plus insert stements to populate the initial master data into a text file. CursiveDB allows you to run this file against a database just like SQL Management Studio where blocks of SQL statements can be executed together by separating them from other blocks using the 'GO' keyword.
using (SqlConnection conn = GetConnection()) { conn.Open(); string script = "c:\\test\insert_rows.sql"; conn.ExecuteSqlScript(script, true); conn.Close(); }Open source
CursiveDB is open source, you can either download the binaries or download the source code from gitlab. CursiveDB binary download comes with first-class help in .CHM format.
Usage help
The binary download of CursiveDB comes with a CHM help file which explains the syntax of methods as well as provides sample code. Coming soon - a quick-start blog which is a great starting point for using CursiveDB.Pre-requisite software
- .NET SDK 4.5
- A development tool like Visual Studio