PublicUtility.Sql
2.0.0
Prefix Reserved
See the version list below for details.
dotnet add package PublicUtility.Sql --version 2.0.0
NuGet\Install-Package PublicUtility.Sql -Version 2.0.0
<PackageReference Include="PublicUtility.Sql" Version="2.0.0" />
paket add PublicUtility.Sql --version 2.0.0
#r "nuget: PublicUtility.Sql, 2.0.0"
// Install PublicUtility.Sql as a Cake Addin #addin nuget:?package=PublicUtility.Sql&version=2.0.0 // Install PublicUtility.Sql as a Cake Tool #tool nuget:?package=PublicUtility.Sql&version=2.0.0
Extension
Class library with SQL manipulation facilitator in multiple database types
Installation
To install, just run the C# compiler to generate the .dll file and once the file has been generated, just add the reference to the project or use Nuget or in nuget console, use the following command:
install-Package PublicUtility.Sql
DB Class
Class used for work with sql server database. Simplified methods that use sql transaction to complete activities securely. Below are examples of usage.
How to use - SQLSERVER:
using PublicUtility.Sql.SqlServer;
// ************* USE EXAMPLE 1 ************
using var conn = DB.GetConn("myConnString"); // opens a new Sql server connection
var query = new StringBuilder();
var cmd = new SqlCommand();
query.AppendLine("SELECT * FROM MYTABLE");
query.AppendLine("WHERE ID = @ID");
cmd.CommandText = query.ToString();
cmd.Parameters.AddWithValue("ID", 10);
var dataTable = conn.ReturnData(cmd);
// ************* USE EXAMPLE 2 ************
using var conn = DB.GetConn("myConnString"); // opens a new Sql server connection
var query = "UPDATE MY TABLE SET NAME = NEWNAME WHERE ID = @ID";
var cmd = new SqlCommand();
cmd.CommandText = query.ToString();
cmd.Parameters.AddWithValue("ID", 10);
cmd.Parameters.AddWithValue("NEWNAME", "IS A TEST NAME");
conn.ExecCmd(cmd);
// ************* USE EXAMPLE 3 ************
using var conn = DB.GetConn("myConnString"); // opens a new Sql server connection
var query = "SELECT * FROM MYTABLE";
var dataTable = conn.ReturnData(query);
How to use - MYSQL:
using PublicUtility.Sql.MySql;
// CONFIGURATION FOR CONNECTING TO THE SERVER.
var builder = new MySqlConnectionStringBuilder() {
Server = "localhost",
Database = "dbmysql",
UserID = "root",
Password = "",
Port = 3306,
SslMode = MySqlSslMode.Required
};
// ************* USE EXAMPLE 1 ************
using var con = DB.GetConn(builder);
var dataTable = con.ReturnData("SELECT * FROM DBTESTE");
// ************* USE EXAMPLE 2 ************
using var con = DB.GetConn(builder);
var resultOk = con.ExecQuery("INSERT INTO dbTeste VALUES(default, 'test')");
// ************* USE EXAMPLE 2 ************
using var con = DB.GetConn(builder);
var query = new StringBuilder();
var cmd = new MySqlCommand();
query.Append("INSERT INTO DBTESTE VALUES ");
query.Append(" (@default, @name01)");
query.Append(", (@default, @number01)");
cmd.CommandText = query.ToString();
cmd.Parameters.AddWithValue("name01", "test01");
cmd.Parameters.AddWithValue("number01", 010101);
cmd.Parameters.AddWithValue("default", default);
var resultOk = con.ExecCmd(cmd);
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
License
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net7.0
- Microsoft.Data.SqlClient (>= 5.0.1)
- MongoDB.Driver (>= 2.18.0)
- MySqlConnector (>= 2.2.4)
- Npgsql (>= 7.0.1)
- PublicUtility.Extension (>= 2.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Inclusion of the Postegresql module, inclusion of async methods.