Voyager.DBConnection 4.3.1

dotnet add package Voyager.DBConnection --version 4.3.1
                    
NuGet\Install-Package Voyager.DBConnection -Version 4.3.1
                    
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="Voyager.DBConnection" Version="4.3.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Voyager.DBConnection" Version="4.3.1" />
                    
Directory.Packages.props
<PackageReference Include="Voyager.DBConnection" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Voyager.DBConnection --version 4.3.1
                    
#r "nuget: Voyager.DBConnection, 4.3.1"
                    
#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.
#addin nuget:?package=Voyager.DBConnection&version=4.3.1
                    
Install Voyager.DBConnection as a Cake Addin
#tool nuget:?package=Voyager.DBConnection&version=4.3.1
                    
Install Voyager.DBConnection as a Cake Tool

Voyager.DBConnection

Library providing connection to SQL database using DbProviderFactory.

How to use it

Implement interface Voyager.DBConnection.Interfaces.ICommandFactory:

	public interface ICommandFactory : IReadOutParameters
	{
		DbCommand ConstructDbCommand(Database db);
	}

Example code is like:

	internal class SetPilotiDoPowiadomieniaFactory : Voyager.DBConnection.Interfaces.ICommandFactory
	{
		private readonly int idBusMapRNo;
		private readonly DateTime busMapDate;
		private readonly string idAkwizytor;
		private readonly string raport;

		public SetPilotiDoPowiadomieniaFactory(int idBusMapRNo, DateTime busMapDate, string idAkwizytor, string raport)
		{
			this.idBusMapRNo = idBusMapRNo;
			this.busMapDate = busMapDate;
			this.idAkwizytor = idAkwizytor;
			this.raport = raport;
		}
		public DbCommand ConstructDbCommand(Database db)
		{
			var cmd = db.GetStoredProcCommand("BusMap.p_SetPilotiDoPowiadomienia");
			db.AddInParameter(cmd, "IdBusMapRNo", DbType.Int32, this.idBusMapRNo);
			db.AddInParameter(cmd, "BusMapDate", DbType.Date, this.busMapDate);
			db.AddInParameter(cmd, "IdAkwizytor", DbType.AnsiString, this.idAkwizytor);
			db.AddInParameter(cmd, "Raport", DbType.AnsiString, this.raport);

			return cmd;
		}

		public void ReadOutParameters(Database db, DbCommand command)
		{
		}
	}

Using your DbProviderFactory create your type of database object Voyager.DBConnection.Database and Voyager.DBConnection.Connection. On the connection object call ExecuteNonQuery the command factory:

			SetPilotiDoPowiadomieniaFactory factory = new SetPilotiDoPowiadomieniaFactory(tagItem.IdBusMapRNp, tagItem.BusMapDate, tagItem.IdAkwizytor, tagItem.Raport);
			con.ExecuteNonQuery(factory);

For reading data implement IGetConsumer interface:

internal class RegionalSaleCommand : Voyager.DBConnection.Interfaces.ICommandFactory, IGetConsumer<SaleItem[]>
	{
		private RaportRequest request;

		public RegionalSaleCommand(RaportRequest request)
		{
			this.request = request;
		}
		public DbCommand ConstructDbCommand(Database db)
		{
			var cmd = db.GetStoredProcCommand("[dbo].[TestSaleReport]");
			db.AddInParameter(cmd, "IdAkwizytorRowNo", System.Data.DbType.Int32, request.IdAkwizytorRowNo);
			db.AddInParameter(cmd, "IdPrzewoznikRowNo", System.Data.DbType.Int32, request.IdPrzewoznikRowNo);
			db.AddInParameter(cmd, "DataPocz", System.Data.DbType.DateTime, request.DateFrom);
			db.AddInParameter(cmd, "DataKon", System.Data.DbType.DateTime, request.DateTo);

			return cmd;
		}

		public SaleItem[] GetResults(IDataReader dataReader)
		{
			List<SaleItem> lista = new List<SaleItem>();

			while (dataReader.Read())
			{
				int col = 0;
				SaleItem item = new SaleItem();
				item.GidRezerwacji = dataReader.GetString(col++);
				item.GIDL = dataReader.GetString(col++);

				DateTime data = dataReader.GetDateTime(col++);

				var ts = dataReader.GetValue(col++);

				TimeSpan czas = ts.ToString().CastTimeSpan();

				item.DataSprzedazy = data.AddTicks(czas.Ticks);
				item.IdWaluta = dataReader.GetString(col++);
				item.IdWalutaBazowa = DBSafeCast.CastEmptyString(dataReader.GetValue(col++));
				item.KursDniaBaz = (Double)DBSafeCast.Cast<Decimal>(dataReader.GetValue(col++), 1);
				item.NettoZ = DBSafeCast.Cast<Decimal>(dataReader.GetValue(col++), 0);
				item.WalutaZcennika = dataReader.GetBoolean(col++);

				lista.Add(item);
			}


			return lista.ToArray();
		}

		public void ReadOutParameters(Database db, DbCommand command)
		{

		}
	}

Next, call the GetReader method:

		public class RaportDB : Voyager.Raport.DBEntity.Store.Raport
	{
		private readonly Connection connection;

		public RaportDB(Voyager.DBConnection.Connection connection)
		{
			this.connection = connection;
		}
		public RaportResponse GetRaport(RaportRequest request)
		{
			RegionalSaleCommand raport = new RegionalSaleCommand(request);
			return new RaportResponse()
			{
				Items = connection.GetReader(raport, raport)
			};
		}
	}

Logging

There is an extension used to log operations. Voyager.DBConnection.Logging. After installing on the connection obcjet is needed to call extension:


namespace Voyager.DBConnection
{
	public static class ConnectionLogger
	{
		public static void AddLogger(this Connection connection, ILogger logger)
		{
			connection.AddFeature(new LogFeature(logger, connection));
		}
	}
}

MS Sql provider

For using MS SQL Provider is prepared the Nuget Voyager.DBConnection.MySql. There is provided implementation of the connection object:

namespace Voyager.DBConnection.MsSql
{
	public class SqlConnection : Connection
	{
		public SqlConnection(string sqlConnectionString) : base(new SqlDatabase(sqlConnectionString), new ExceptionFactory())
		{
		}
	}
}

✍️ Authors

  • @andrzejswistowski - Idea & work. Please let me know if you find out an error or suggestions.

contributors.

🎉 Acknowledgements

  • Przemysław Wróbel - for the icon.
Product 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 is compatible.  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. 
.NET Framework net48 is compatible.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.8

    • No dependencies.
  • net6.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Voyager.DBConnection:

Package Downloads
Voyager.DBConnection.MsSql

Implementation MS Sql extension for Voyager.DBConnection

Voyager.DBConnection.Logging

Logging extension for Voyager.DBConnection

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.3.1 184 10/18/2024
4.2.3 110 10/17/2024
4.2.2 98 10/17/2024
4.1.5 721 3/5/2024
4.1.3 134 3/5/2024
4.1.2 582 12/5/2023
4.1.1 162 12/5/2023
4.1.0 213 11/22/2023
4.0.3 180 11/13/2023
4.0.0 179 10/31/2023
3.0.1 230 5/5/2023
3.0.0 158 5/5/2023