Code Monkey home page Code Monkey logo

brook's Introduction

brook

A high performance micro sql helper supporting SQL Server、MySql、PostgreSQL

NuGet

Supported .NET Framework 4.6.1、.NET Standard 2.0 and .NET Standard 2.1

Usage

Quick Start

  1. Install Nuget package. here.

  2. For .NET Framework project, Add some parameters in web.conf or app.config. Parameters format like below.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <sectionGroup name="jIAnSoft">
      <section name="framework" type="jIAnSoft.Brook.Configuration.Section, Brook"/>
    </sectionGroup>
  </configSections>
  <jIAnSoft>
    <framework>
      <common name="BrookDemo" culture="zh-TW" timezone="Tokyo Standard Time"/>
      <database>
        <!-- sql server -->
        <add name="mssql" connection="server=127.0.0.1;database=DbName;uid=sa;pwd=7533967" providerName="System.Data.SqlClient"/>
        <add name="sqlserver" connection="server=127.0.0.1;database=DbName;uid=sa;pwd=7533967" providerName="Microsoft.Data.SqlClient"/>
        <!-- If use MySql, It's need download driver https://www.nuget.org/packages/MySql.Data/6.9.9 -->
        <add name="mysql" connection="server=127.0.0.1;uid=root;pwd=7533967;database=DbName" providerName="MySql.Data.MySqlClient"/>
        <!-- If use PostgreSQL need download driver https://www.nuget.org/packages/Npgsql/-->
        <add name="postgresql" connection="Host=127.0.0.1;uid=postgres;pwd=7533967;database=DbName" providerName="Npgsql"/>
        <add name="sqlite" connection="data source=.\\brook.sqlite" providerName="System.Data.SQLite" commandTimeout="5" />
      </database>
    </framework>
  </jIAnSoft>
  <system.data>
    <DbProviderFactories>
        <!-- If use MySQL, Need register MySql's provider factory-->
        <remove invariant="MySql.Data.MySqlClient" />
        <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data" />     
        <!-- If use PostgreSQL, Need register Npgsql's provider factory -->
        <remove invariant="Npgsql"/>
        <add name="Npgsql Data Provider" invariant="Npgsql" description="Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql" />
        <remove invariant="System.Data.SQLite" />
        <add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />     
        <remove invariant="Microsoft.Data.SqlClient" />
        <add name="Microsoft SqlClient Data Provider" invariant="Microsoft.Data.SqlClient" description=".Net Framework Data Provider for SqlServer" type="Microsoft.Data.SqlClient.SqlClientFactory, Microsoft.Data.SqlClient" />
    </DbProviderFactories>
  </system.data>  
</configuration>

3.Use examples

//Get query data as DataSet
var postgreDs = Brook.Load("postgresql").DataSet("select * FROM public.account;select * FROM public.account;");

//Get query data as DataTable
var postgreTable = Brook.Load("postgresql").Table("select * FROM public.account;");
var mysqlTable = Brook.Load("mysql").Table(
    "SELECT `id`,`email`,`name` FROM `account` WHERE `id` = @id;",
    new DbParameter[]
    {
        new MySqlParameter("@id", MySqlDbType.Int32)
        {
            Value = 1
        }
    });

//Insert、Update、Delete operation 
var count = Brook.Load("mysql").Execute(
    "INSERT INTO `account`(`id`,`email`,`name`)VALUES(@id,@email,@name);"
    new DbParameter[]
    {
        new MySqlParameter("@id", MySqlDbType.Int32)
        {
            Value = 1
        },
        new MySqlParameter("@email", MySqlDbType.VarChar)
        {
            Value = "[email protected]"
        },
        new MySqlParameter("@name", MySqlDbType.VarChar)
        {
            Value = "example"
        }
    });
var count = Brook.Load("mssql").Execute("DELETE FROM [account] WHERE [Id] = 0");
var one = Brook.Load("mssql").One<int>("SELECT COUNT(*) FROM Account");
var obj = Brook.Load("mssql").First<Account>("SELECT [Id],[Name],[Email] FROM [account] WHERE Id=1");
var objs = Brook.Load("mssql").Query<Account>("SELECT [Id],[Name],[Email] FROM [account]");

public class Account
{
    public long Id { get; set; }
    public string Email { get; set; }
    public string Name { get; set; }
}

You can see more example code in the example projects.

License

Copyright (c) 2017

Released under the MIT license:

brook's People

Contributors

jiansoft avatar dependabot[bot] avatar

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.