Giter Club home page Giter Club logo

directsql's Introduction

What is this for ?

Build Status
CodeFactor
Ready on NuGet

Execute SQL directly !

This .NET library is very thin database framework on top of System.Data. In this library, you can use SQL directly without taking care for lifecycle of connection, transaction and so on.

In many database framework, direct execution of SQL is more or less barriered from orthodox. This library resolve issues around that.

Please try ๐Ÿ˜„.

Where to start

This library prepare corresponding Database class for supporting RDBMS

  • DirectSQL.SqlLite.SqlLiteDatabase (SQLite)
  • DirectSQL.SqlServer.SqlServerDatabase (SQL Server)
  • DirectSQL.npgsql.NpgsqlDatabase (PostgreSQL, CockroachDB)
  • DirectSQL.DB2.DB2Database (DB2)
  • DirectSQL.MySql.MySqlDatabase (MySql)
  • DirectSQL.Odbc.OdbcDatabase (ODBC connected DBMS)

These Database classes are entry point of this library.

Documentation

Documentation is here.

Examples

Example1

public static void example()
{
    SqlLiteDatabase db = new SqlLiteDatabase("connectionString_to_yourdb");
    db.Process((connection) =>
    {
        SqlLiteDatabase.Query(
            "select TEST_VAL1,TEST_VAL2 from TEST_TABLE where TEST_VAL1 = @val1",
            new (String, object)[] {("@val1","abcdef")},
            connection,
            (result) => {
                while (result.Next())
                {
                    var resultValues = result.ResultValues;
                    Console.Out.WriteLine("TEST_VAL1:" + resultValues.TEST_VAL1);
                    Console.Out.WriteLine("TEST_VAL2:" + resultValues.TEST_VAL2);
                }
            }
        );
    });
}

Example2

public static void example2()
{
    SqlLiteDatabase db = new SqlLiteDatabase("connectionString_to_yourdb");
    db.Process((connection) =>
    {
        dynamic[] resultArray =
            SqlLiteDatabase
            .LoadSqlResult(
                "select TEST_COL1,TEST_COL2 from TEST_TABLE",
                connection);
        
        Console.Out.WriteLine("TEST_VAL1:" + resultArray[0].TEST_VAL1);
        Console.Out.WriteLine("TEST_VAL2:" + resultArray[0].TEST_VAL2);
    });
}

How to build and test

 git clone [email protected]:DirectSQL/DirectSQL.git
 cd DirectSQL
 dotnet build
 dotnet test

directsql's People

Contributors

7k8m avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

directsql's Issues

In environments other than Windows, "TransactionAsync" fails.

Evidence of problem

Run dotnet test --configuration Release
Test run for /home/runner/work/DirectSQL/DirectSQL/TestSqlLiteDatabase/bin/Release/netcoreapp3.1/TestSqlLiteDatabase.dll(.NETCoreApp,Version=v3.1)
Microsoft (R) Test Execution Command Line Tool Version 16.3.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...

A total of 1 test files matched the specified pattern.
The active test run was aborted. Reason: Test host process crashed : Unhandled exception. System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'SQLiteConnection'.
   at System.Data.SQLite.SQLiteConnection.CheckDisposed()
   at System.Data.SQLite.SQLiteConnection.get_State()
   at System.Data.SQLite.SQLiteTransactionBase.IsValid(Boolean throwError)
   at System.Data.SQLite.SQLiteTransactionBase.Dispose(Boolean disposing)
   at System.Data.SQLite.SQLiteTransaction.Dispose(Boolean disposing)
   at System.Data.Common.DbTransaction.Dispose()
   at DirectSQL.Database`5.TransactionAsync(C connection, AsyncSqlExecution`2 execute) in /home/runner/work/DirectSQL/DirectSQL/DirectSQL/Database.cs:line 413
   at TestSqlLiteDatabase.TransactionTest.<>c.<<TestTransactionAsync>b__1_0>d.MoveNext() in /home/runner/work/DirectSQL/DirectSQL/TestSqlLiteDatabase/TransactionTest.cs:line 78
--- End of stack trace from previous location where exception was thrown ---
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__139_1(Object state)
   at System.Threading.QueueUserWorkItemCallbackDefaultContext.Execute()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

Run dotnet test --configuration Release
Test run for D:\a\DirectSQL\DirectSQL\TestSqlLiteDatabase\bin\Release\netcoreapp3.1\TestSqlLiteDatabase.dll(.NETCoreApp,Version=v3.1)
Microsoft (R) Test Execution Command Line Tool Version 16.3.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...

A total of 1 test files matched the specified pattern.

Test Run Successful.
Total tests: 18
     Passed: 18
 Total time: 2.2834 Seconds

One possibility

In .NET Core other than Windows, implementation of transaction might have some problem around async / await.
Something like disposing transaction, when thread suspended, might be happened inside dotnet. ๐Ÿ˜ข

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.