Ridavei.Settings.DbAbstractions 2.0.0

dotnet add package Ridavei.Settings.DbAbstractions --version 2.0.0                
NuGet\Install-Package Ridavei.Settings.DbAbstractions -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="Ridavei.Settings.DbAbstractions" Version="2.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Ridavei.Settings.DbAbstractions --version 2.0.0                
#r "nuget: Ridavei.Settings.DbAbstractions, 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 Ridavei.Settings.DbAbstractions as a Cake Addin
#addin nuget:?package=Ridavei.Settings.DbAbstractions&version=2.0.0

// Install Ridavei.Settings.DbAbstractions as a Cake Tool
#tool nuget:?package=Ridavei.Settings.DbAbstractions&version=2.0.0                

Ridavei.Settings.DbAbstractions

Latest release

NuGet Badge Ridavei.Settings.DbAbstractions

Library that contains abstract classes for manager and settings retriever used to connect to the database.

Using IDbConnection as parameter it's checked if the connection is broken or closed. If it's' broken then Close method is called. If the connection is in the closed state then it will be opened and closed as needed.

Example of use

Creating classes to load data from SQL Server

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

using Ridavei.Settings.DbAbstractions.Managers;
using Ridavei.Settings.DbAbstractions.Settings;

namespace Example
{
    internal sealed class SqlServerConnectionManager : ADbConnectionManager
    {
        public SqlServerConnectionManager(IDbConnection connection) : base(connection) { }

        protected override ADbSettings CreateDbSettings(string dictionaryName)
        {
            return new SqlServerSettings(dictionaryName);
        }

        protected override bool TryGetDbSettingsObject(string dictionaryName, out ADbSettings settings)
        {
            settings = CreateDbSettings(dictionaryName);
            return true;
        }
    }

    internal sealed class SqlServerProviderFactoryManager : ADbProviderFactoryManager
    {
        public SqlServerProviderFactoryManager(string connectionString) : base(SqlClientFactory.Instance, connectionString) { }

        protected override ADbSettings CreateDbSettings(string dictionaryName)
        {
            return new SqlServerSettings(dictionaryName);
        }

        protected override bool TryGetDbSettingsObject(string dictionaryName, out ADbSettings settings)
        {
            settings = CreateDbSettings(dictionaryName);
            return true;
        }
    }

    internal sealed class SqlServerSettings : ADbSettings
    {
        public SqlServerSettings(string dictionaryName) : base(dictionaryName) { }

        protected override int AddOrUpdateValueInDb(IDbConnection connection, string key, string value)
        {
            using (IDbCommand cmd = connection.CreateCommand())
            {
                cmd.CommandText = "QUERY";

                return cmd.ExecuteNonQuery();
            }
        }

        protected override IReadOnlyDictionary<string, string> GetAllValuesFromDb(IDbConnection connection)
        {
            Dictionary<string, string> res = new Dictionary<string, string>();
            using (IDbCommand cmd = connection.CreateCommand())
            {
                cmd.CommandText = "QUERY";

                using (var reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                        res.Add(reader.GetString(0), reader.IsDBNull(1) ? string.Empty : reader.GetString(1));
                }
            }

            return res;
        }

        protected override bool TryGetValueFromDb(IDbConnection connection, string key, out string value)
        {
            value = string.Empty;
            using (IDbCommand cmd = connection.CreateCommand())
            {
                cmd.CommandText = "QUERY";

                var obj = cmd.ExecuteScalar();
                if (obj != null && obj != DBNull.Value)
                {
                    value = obj.ToString();
                    return true;
                }
                return false;
            }
        }
    }
}

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net452 is compatible.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Ridavei.Settings.DbAbstractions:

Package Downloads
Ridavei.Settings.SqlServer

Builder extension to store settings keys and values in SQL Server database.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.0 320 4/18/2023
1.0.0 216 11/29/2022