Need help with DbUtility?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

Ivony
206 Stars 76 Forks Apache License 2.0 212 Commits 4 Opened issues

Description

a light database access tool

Services available

!
?

Need anything else?

Contributors list

# 202,201
C#
HTML
200 commits
# 87,911
C#
Redis
dotnet-...
ocelot
1 commit

DataPithy

DataPithy is a light database access tool

How to use

execute a query

CSharp
db.T( "SELECT * FROM Members" ).ExecuteDataTable();

execute a query with parameter and return first row

CSharp
db.T( "SELECT FirstName, LastName FROM Members WHERE Username = {0}", username ).ExecuteFirstRow();

execute a query as async.

CSharp
await db.T( "SELECT FirstName, LastName FROM Members WHERE Username = {0}", username ).ExecuteFirstRowAsync();

Basic concept

db.T( "SELECT FirstName, LastName FROM Members WHERE Username = {0}", username ).ExecuteFirstRow();

In the code above,

db
is called database executor,
T( "SELECT FirstName, LastName FROM Members WHERE Username = {0}", username )
is called query definition,
and
ExecuteFirstRow()
is called result definition

The following code creates a database executor

CSharp
var db = SqlServer.Create( "connection-string-name" );
Or
CSharp
var db = SqlServer.Connect( "connection-string" );

database executor is responsible for createing connection and executing queries.


A typical query definition like this below

CSharp
db.T( "query-text-template", params parameters );
The query text is SQL command to be executed. and you can use parameter placehold inside like
string.Format
syntax. like this below:
CSharp
db.T( "SELECT MemberID FROM Members WHERE Username = {0} AND Password = {1}", username, password )
it will create a SQL query like this below:
SQL
DECLARE @Param0 AS nvarchar = 'text of username';
DECLARE @Param1 AS nvarchar = 'text of password';
SELECT MemberID FROM Members WHERE Username = @Param0 AND Password = @Param1;
the method name T means Template, so we can also write code like below:
CSharp
db.Template( "SELECT MemberID FROM Members WHERE Username = {0} AND Password = {1}", username, password )
and the T is an extension method, you can declare another query definition method as you like.

In the last, we talk about the result definition. like same as the query definition, result definition are also en extension method. we have many result definition method, and all of they have asynchronous version. the popular result definition method under this:

ExecuteNonQuery, execute query, and return the number of rows affected.
ExecuteScaler, execute query and return the first column of the first row.
ExecuteDataTable, execute query and fill a DataTable and return.
ExecuteFirstRow, execute query and return ths first row.
ExecuteEntity, execute query and return the first row to fill the specified type of entity

Get It

you can download last stable release from nuget: DataPithy

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.