Newsbot.Collector/Newsbot.Collector.Database/Repositories/SettingsTable.cs
James Tombleson 17e97b4e09
Features/table clients (#5)
* inital table clients are almost ready

* adding new repo interfaces

* adding MS DI to the tables

* adding tables and MS DI to jobs

* updated how the config builder works and pass Iconfig to jobs

* Updated how articles interface returns a value

* updated constructors to support DI and removed static call

* added source consts and model notes

* updated sources.type to contain the value to link what job collects it

* added RssWatcherJob to hangfire

* DI and hangfire jobs wont work.  Defering to options classes

* Services updated to have options exposed over DI

* Tests have been updated.. more to come
2023-02-19 21:39:03 -08:00

44 lines
1.0 KiB
C#

using System.Data;
using Dapper;
using Microsoft.Extensions.Configuration;
using Newsbot.Collector.Domain.Models;
using Npgsql;
namespace Newsbot.Collector.Database.Repositories;
public class SettingsTable
{
private string _connectionString;
public SettingsTable(string connectionString)
{
_connectionString = connectionString;
}
public SettingsTable(IConfiguration configuration)
{
var connstr = configuration.GetConnectionString("database");
if (connstr is null)
{
connstr = "";
}
_connectionString = connstr;
}
private IDbConnection OpenConnection(string connectionString)
{
var conn = new NpgsqlConnection(_connectionString);
conn.Open();
return conn;
}
public void New(SettingModel model)
{
model.ID = Guid.NewGuid();
using var conn = OpenConnection(_connectionString);
var q = @"Insert Into Settings (ID, Key, Value, OPTIONS) Values (@ID,@Key,@Value,@Options)";
conn.Execute(q, model);
}
}