OOP-SQL-Library
1.0.0
dotnet add package OOP-SQL-Library --version 1.0.0
NuGet\Install-Package OOP-SQL-Library -Version 1.0.0
<PackageReference Include="OOP-SQL-Library" Version="1.0.0" />
<PackageVersion Include="OOP-SQL-Library" Version="1.0.0" />
<PackageReference Include="OOP-SQL-Library" />
paket add OOP-SQL-Library --version 1.0.0
#r "nuget: OOP-SQL-Library, 1.0.0"
#:package OOP-SQL-Library@1.0.0
#addin nuget:?package=OOP-SQL-Library&version=1.0.0
#tool nuget:?package=OOP-SQL-Library&version=1.0.0
Relational-Databases-via-OOP
About project
- This is a simple SQL library that I made as part of my learning new things in Unity and strict OOP Research
- In fact, this is just a wrapper over another library - Npgsql
- The library contains classes for using basic SQL commands(CRUD), but allows you to execute any command in any mode
Specifics
- Project using OOP and SOLID
- Procedural SQL algorithms deisgned to be true OOP
- Clearest DI and SRP
- My first library that I published
How to install
cd DirectoryWithYourProject
dotnet add package Simple-ORM
dotnet restore
Or you can just install package from this site
How to use
RelationalDatabase
To get started, you will need to create the RelationalDatabase and DatabaseParametersStringFactory components. The first one allows you to query a relational database in any mode (NonQuery, Scalar, Reader and async versions of them) and has an IDatabase interface, while the second one is used by other components for convenience and has an IDatabaseParametersStringFactory interface. You won't need it to run queries directly.
var database = new RelationalDatabase(@"Server=your server;Port=your port;User Id=your user id;Password=your password;Database=your DB name");
var parametersStringFactory = new DatabaseParametersStringFactory();
RelationalDatabaseValue
Also, for all components, you will need objects of the RelationalDatabaseValue class, which has the IDatabaseValue interface and is a name-value pair with validation, isolation and other cool things 😉
var value = new RelationalDatabaseValue("first_name", "Anatoliy");
RelationalDatabaseDataWriter
RelationalDatabaseDataWriter allows you to write data to your relational database and has the IDatabaseDataWriter interface. It only takes 2 arguments: the name of your database and the IDatabaseValues to be inserted.
var relationalDatabaseDataWriter = new RelationalDatabaseDataWriter(database, parametersStringFactory);
IDatabaseValue[] values = { new RelationalDatabaseValue("age", 19), new RelationalDatabaseValue("first_name", "Anatoliy"), new RelationalDatabaseValue("last_name", "Oleynikov") };
relationalDatabaseDataWriter.WriteData("humans", values); //equals to "INSERT INTO humans (age, first_name, last_name) VALUES (19, 'Anatoliy', 'Oleynikov')"
RelationalDatabaseDataReader
RelationalDatabaseDataReader allows you to read data from your relational database and has the IDatabaseDataReader interface. It takes 3 arguments: the name of the table, the names of the columns to be selected (optional, if you pass an empty array, then in the final query will be *), and the IDatabaseValues by which the data will be selected (optional).
var relationalDatabaseDataReader = new RelationalDatabaseDataReader(database, parametersStringFactory);
DataTable dataTable = relationalDatabaseDataReader.GetData("humans", new string[] { }); //equals to "SELECT * FROM humans"
dataTable = relationalDatabaseDataReader.GetData("humans", new[] { "first_name" }, new IDatabaseValue[] { new RelationalDatabaseValue("age", 19) }); //equals to "SELECT first_name FROM humans WHERE age = 19"
RelationalDatabaseDataUpdater
RelationalDatabaseDataUpdater allows you to update data in your relational database and has the IDatabaseDataUpdater interface. It takes 3 arguments, of which 2 are required: the name of the database and the IDatabaseValues by which the data will be replaced. The third argument is the IDatabaseValues that will be updated. If this argument is missing, all data in the table will be replaced, be careful.
var relationalDatabaseDataUpdater = new RelationalDatabaseDataUpdater(database, parametersStringFactory);
var replacedArguments = new IDatabaseValue[] { new RelationalDatabaseValue("age", 20) };
var argumentsWhichChanging = new IDatabaseValue[] { new RelationalDatabaseValue("first_name", "Anatoliy") };
relationalDatabaseDataUpdater.UpdateData("humans", replacedArguments, argumentsWhichChanging); //equals to "UPDATE humans SET age = 20 WHERE first_name = 'Anatoliy'"
relationalDatabaseDataUpdater.UpdateData("humans", replacedArguments); //equals to "UPDATE humans SET age = 20"
RelationalDatabaseDataDeleter
RelationalDatabaseDataDeleter allows you to delete data from your relational database and has the IDatabaseDataDeleter interface. It takes 2 arguments: the name of the database and the IDatabaseValues by which the data will be deleted.
var relationalDatabaseDataDeleter = new RelationalDatabaseDataDeleter(database, parametersStringFactory);
IDatabaseValue[] values = { new RelationalDatabaseValue("age", 19), new RelationalDatabaseValue("first_name", "Anatoliy"), new RelationalDatabaseValue("last_name", "Oleynikov") };
relationalDatabaseDataDeleter.DeleteData("humans", values); //equals to "DELETE FROM humans WHERE age = 19 AND first_name = 'Anatoliy' AND last_name = 'Oleynikov'"
Conclusion
Now you know how to install and use the components of this library. Don't forget that if the library's CRUD components don't allow you to execute the commands you need or don't allow you to do all the necessary actions in one query, then you can always use RelationalDatabase, which reduces command execution to one line and allows you to use the full power of SQL. Thanks for reading this and using the library. Good luck with your projects!
From Atennop with OOP and ❤ <br>Thanks to Farid for the good renaming according to all the canons of OOP
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net6.0
- Npgsql (>= 8.0.0-preview.3)
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 |
|---|