Newsbot.Collector/Newsbot.Collector.Database/Repositories/SettingsTable.cs
James Tombleson 9f3a6323a6
Features/html meta extractor (#4)
* gave api access to the db project

* added db models

* working on rss extraction and meta extraction

* test project to debug rsswatcherjob

* added new configs for the project

* new interface to define collectors

* basic rss extraction and article details are now exposed

* tests updated for rss pull

* starting to get dapper working.  Query works but insert seems to have a value issue

* removed dapper from services

* added some basic tests for db calls
2023-02-16 22:19:05 -08:00

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