seay - GodSharp.Data.Common.DbProvider 1.0.0-preview1

DbProviderFactory Factory libary for .NET Core.

PM> Install-Package GodSharp.Data.Common.DbProvider -Version 1.0.0-preview1 -Source https://www.myget.org/F/seay/api/v3/index.json

Copy to clipboard

> nuget.exe install GodSharp.Data.Common.DbProvider -Version 1.0.0-preview1 -Source https://www.myget.org/F/seay/api/v3/index.json

Copy to clipboard

> dotnet add package GodSharp.Data.Common.DbProvider --version 1.0.0-preview1 --source https://www.myget.org/F/seay/api/v3/index.json

Copy to clipboard
<PackageReference Include="GodSharp.Data.Common.DbProvider" Version="1.0.0-preview1" />
Copy to clipboard
source https://www.myget.org/F/seay/api/v3/index.json

nuget GodSharp.Data.Common.DbProvider  ~> 1.0.0-preview1
Copy to clipboard

> choco install GodSharp.Data.Common.DbProvider --version 1.0.0-preview1 --source https://www.myget.org/F/seay/api/v2

Copy to clipboard
Import-Module PowerShellGet
Register-PSRepository -Name "seay" -SourceLocation "https://www.myget.org/F/seay/api/v2"
Install-Module -Name "GodSharp.Data.Common.DbProvider" -RequiredVersion "1.0.0-preview1" -Repository "seay" -AllowPreRelease
Copy to clipboard

GodSharp.Data.Common.DbProvider

DbProviderFactory Factory libary for .NET Core.

AppVeyor build status NuGet MyGet

Supported netstandard1.3 and netstandard2.0.

Getting Started

  1. Install Nuget Package.

See here.

  1. Add Json Parameters.

You can add to any json file,and then add this file.

Parameters format like below.

{
  "DbConnectionStrings": [
    {
      "name": "mssql",
      "connectionString": "Data Source=localhost;Initial Catalog=Master;User Id=sa;Password=1234;",
      "providerName": "System.Data.SqlClient"
    },
    {
      "name": "mysql",
      "connectionString": "Data Source=localhost;Initial Catalog=user;User Id=root;Password=1234;",
      "providerName": "Pomelo.Data.MySql"
    },
    {
      "name": "sqlite",
      "connectionString": "Data Source=data.db",
      "providerName": "Microsoft.Data.Sqlite"
    },
    {
      "name": "pgsql",
      "connectionString": "Host=localhost;Database=postgres;Username=postgres;Password=1234;",
      "providerName": "Npgsql"
    }
  ],
  "DbProviderFactories": [
    {
      "name": "SqlClient Data Provider",
      "invariant": "System.Data.SqlClient",
      "description": ".Net Framework Data Provider for SqlServer",
      "type": "System.Data.SqlClient.SqlClientFactory, System.Data.SqlClient"
    },
    {
      "name": "MySQL Data Provider by Pomelo",
      "invariant": "Pomelo.Data.MySql",
      "description": ".Net Framework Data Provider for MySql",
      "type": "Pomelo.Data.MySql.MySqlClientFactory, Pomelo.Data.MySql"
    },
    {
      "name": "SQLite Data Provider",
      "invariant": "Microsoft.Data.Sqlite",
      "description": ".Net Framework Data Provider for SQLite",
      "type": "Microsoft.Data.Sqlite.SqliteFactory, Microsoft.Data.Sqlite"
    },
    {
      "name": "Npgsql Data Provider",
      "invariant": "Npgsql",
      "description": ".Net Framework Data Provider for PostgreSql",
      "type": "Npgsql.NpgsqlFactory, Npgsql"
    }
  ]
}

Tips:DbConnectionStrings section is not required,but I strongly recommend you add this.

  1. Load DbProviders and DbConnectionStrings[option].
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
// add json file
.AddJsonFile("db.provider.json");

var config = builder.Build();

// Load DbProviders and DbConnectionStrings
DbProviderManager.LoadConfiguration(config);
  1. Get DbConnectionString.
DbConnectionStringSetting conn = DbConnectionStringManager.ConnectionStrings["sqlite"];
  1. Get DbConnectionFactory.
DbProviderFactory factory = DbProviderFactories.GetFactory(conn.ProviderName);
  1. Use DbProviderFactory create IDbConnection and other.

Create IDbConnection

IDbConnection db = factory.CreateConnection();

Use IDbConnection.

db.ConnectionString = conn.ConnectionString;
db.Open();

var cmd = db.CreateCommand();
cmd.CommandText = "select datetime('now');";
var dt = cmd.ExecuteScalar();
System.Console.WriteLine(dt);

db.Close();

You can see the full code in test.

  • .NETStandard 1.3
    • Microsoft.Extensions.Configuration (>= 1.1.2)
    • Microsoft.Extensions.Configuration.Binder (>= 1.1.2)
    • Microsoft.Extensions.Configuration.Json (>= 1.1.2)
    • NETStandard.Library (>= 1.6.1)
    • System.Data.Common (>= 4.3.0)
    • System.Reflection.TypeExtensions (>= 4.4.0)
  • .NETStandard 2.0
    • Microsoft.Extensions.Configuration (>= 2.0.0)
    • Microsoft.Extensions.Configuration.Binder (>= 2.0.0)
    • Microsoft.Extensions.Configuration.Json (>= 2.0.0)
  • .NETStandard 1.3: 1.3.0.0
  • .NETStandard 2.0: 2.0.0.0

Owners

Seay

Authors

seayxu

Project URL

https://github.com/godsharp/GodSharp.Data.Common.DbProvider

License

MIT

Tags

DbProvider,DbProviderFactories,GodSharp

Info

1 total downloads
1 downloads for version 1.0.0-preview1
Download (13.99 KB)
Found on the current feed only

Package history

Version Size Last updated Downloads Mirrored?
1.0.0-preview1 13.99 KB Thu, 14 Sep 2017 12:23:33 GMT 1