This commit is contained in:
ana_rchy
2026-03-10 18:53:58 +00:00
commit 573ca15d6f
6 changed files with 246 additions and 0 deletions

86
src/Account.cs Normal file
View File

@@ -0,0 +1,86 @@
using Npgsql;
public class Account {
NpgsqlConnection _connection = new();
public KUID KUID { get; private set; } = new();
public static Account NewAccount(NpgsqlConnection connection, string name) {
KUID kuid = new("special placeholder");
NpgsqlCommand command = new("""
INSERT INTO accounts VALUES (
($1),
($2)
)
""", connection) {
Parameters = {
new NpgsqlParameter<string>() { Value = kuid.Text },
new NpgsqlParameter<string>() { Value = name }
}
};
command.ExecuteNonQuery();
return AccountFromKUID(connection, kuid);
}
public static Account AccountFromKUID(NpgsqlConnection connection, KUID kuid) {
return new() {
_connection = connection,
KUID = kuid
};
}
public void AddPoki(string[] names, int[]? parentIDs = null, string[]? tags = null) {
NpgsqlCommand command = new("""
INSERT INTO poki VALUES (
($1),
DEFAULT,
($2),
($3),
DEFAULT, DEFAULT, DEFAULT,
($4)
)
""", _connection) {
Parameters = {
new() { Value = KUID.Text },
new() { Value = names },
new() { Value = (parentIDs == null ? DBNull.Value : parentIDs) },
new() { Value = (tags == null ? DBNull.Value : tags) },
}
};
command.ExecuteNonQuery();
if (parentIDs == null) {
return;
}
command = new("""
UPDATE poki
SET child_poki = child_poki || currval('poki_id_seq')
WHERE id = ANY($1)
""", _connection) {
Parameters = {
new() { Value = parentIDs }
}
};
command.ExecuteNonQuery();
}
public void GetPokiByName(string name) {
NpgsqlCommand command = new("""
SELECT id
FROM poki
WHERE ($1) IN names
LIMIT 1
""", _connection) {
Parameters = {
new() { Value = name }
}
};
}
}

16
src/KUID.cs Normal file
View File

@@ -0,0 +1,16 @@
using Npgsql;
public class KUID {
public string Text;
// for making a new KUID
public KUID() {
Text = "placeholder";
}
// for making an existing KUID into an object
public KUID(string text) {
Text = text;
}
}

67
src/Poki.cs Normal file
View File

@@ -0,0 +1,67 @@
using Npgsql;
public class Poki {
NpgsqlConnection _connection;
Account _account;
int _id;
string[] _names;
Poki[]? _parentPoki, _childPoki;
bool _fronting, _frontable;
string[]? _tags;
public Poki(
NpgsqlConnection connection,
Account account,
string[] names,
Poki[]? parentPoki = null, Poki[]? childPoki = null,
bool fronting = false, bool frontable = true,
string[]? tags = null
) {
_connection = connection;
_account = account;
_names = names;
_parentPoki = parentPoki; _childPoki = childPoki;
_fronting = fronting; _frontable = frontable;
_tags = tags;
NpgsqlCommand command = new("""
INSERT INTO poki VALUES (
($1),
DEFAULT,
($2),
($3),
($4),
($5),
($6),
($7)
)
""", connection) {
Parameters = {
new() { Value = account.KUID },
new() { Value = names },
new() { Value = parentPoki },
new() { Value = childPoki },
new() { Value = fronting },
new() { Value = frontable },
new() { Value = tags }
}
};
command.ExecuteNonQuery();
command = new("""
SELECT currval('poki_id_seq')
""", connection);
#pragma warning disable CS8605
_id = (int) command.ExecuteScalar();
#pragma warning disable CS8605
}
public static Poki[] GetPokiByName(string name) {
return new Poki[] {};
}
}