PublicUtility.Sql 2.0.0

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
There is a newer version of this package available.
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
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PublicUtility.Sql" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PublicUtility.Sql --version 2.0.0
#r "nuget: PublicUtility.Sql, 2.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.2 591 12/30/2022
2.0.0 573 12/25/2022
1.0.0 571 12/7/2022

Inclusion of the Postegresql module, inclusion of async methods.