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);