using Npgsql; class kulupu { static void Main(string[] args) { NpgsqlConnection connection = ConnectToDatabase(); ClearDatabase(connection); InitDatabase(connection); var account = Account.NewAccount(connection, "ion"); account.AddPoki(new[] { "ana", "kitty" }); account.AddPoki(new[] { "state 1" }, parentIDs: new[] { 1 }); } static NpgsqlConnection ConnectToDatabase() { string connectionString = "Host=/run/postgresql; Username=postgres; Password=; Database=kulupu"; NpgsqlDataSource dataSource = NpgsqlDataSource.Create(connectionString); NpgsqlConnection connection = dataSource.OpenConnection(); return connection; } static void InitDatabase(NpgsqlConnection connection) { NpgsqlCommand command = new(""" CREATE TABLE IF NOT EXISTS accounts ( kuid TEXT NOT NULL, name TEXT NOT NULL ); CREATE TABLE IF NOT EXISTS poki ( account_kuid TEXT NOT NULL, id SERIAL NOT NULL, names TEXT[] NOT NULL, parent_poki INTEGER[], child_poki INTEGER[], fronting BOOLEAN NOT NULL DEFAULT false, frontable BOOLEAN NOT NULL DEFAULT true, tags TEXT[] ); CREATE TABLE IF NOT EXISTS poki_front_history ( poki_id INTEGER NOT NULL, switch_in_times TIMESTAMP[], switch_out_times TIMESTAMP[], notes TEXT[] ) """, connection); command.ExecuteNonQuery(); } static void ClearDatabase(NpgsqlConnection connection) { NpgsqlCommand command = new(""" DROP TABLE IF EXISTS accounts; DROP TABLE IF EXISTS poki; DROP TABLE IF EXISTS poki_front_history """, connection); command.ExecuteNonQuery(); } }