Giter Site home page Giter Site logo

dbutility's Introduction

DataPithy

DataPithy is a light database access tool

How to use

execute a query

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

execute a query with parameter and return first row

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

execute a query as async.

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

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

Or

var db = SqlServer.Connect( "connection-string" );

database executor is responsible for createing connection and executing queries.


A typical query definition like this below

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:

db.T( "SELECT MemberID FROM Members WHERE Username = {0} AND Password = {1}", username, password )

it will create a SQL query like this below:

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:

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

dbutility's People

Contributors

ivony avatar rwing avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dbutility's Issues

sql command timeout

"Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. "

Where can I modify the setting of "SqlCommand.CommandTimeout"?

关于结构化查询抽象

现在 Java 有一个好像叫 JSqlParser 的 SQL 解析器。我觉得 .NET 现在缺少一个这样的模块,如果 DbUtility 能够快点实现就好了。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.