34 lines
876 B
C#
34 lines
876 B
C#
|
using System.Data;
|
||
|
using Dapper;
|
||
|
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 static IDbConnection OpenConnection(string connectionString)
|
||
|
{
|
||
|
var cs = "Host=localhost;Username=postgres;Password=postgres;Database=postgres;sslmode=disable";
|
||
|
var conn = new NpgsqlConnection(cs);
|
||
|
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);
|
||
|
}
|
||
|
}
|