WIP expirementation

This commit is contained in:
eelke 2025-08-18 19:41:36 +02:00
parent fb7dac642a
commit 29a141a971
20 changed files with 307 additions and 62 deletions

View file

@ -1,8 +1,9 @@
using System.Collections.ObjectModel;
using Npgsql;
namespace pgLabII.PgUtils.ConnectionStrings;
public class PqConnectionStringParser
public ref struct PqConnectionStringParser
{
// Note possible keywords
// host
@ -74,5 +75,52 @@ public class PqConnectionStringParser
tokenizer.ConsumeEquals();
string v = tokenizer.GetValue();
result.Add(kw, v);
//switch (kw)
//{
// case "host":
// case "hostaddr":
// result.Host = v.ToString();
// break;
// case "port":
// result.Port = int.Parse(v);
// break;
// case "dbname":
// result.Database = v.ToString();
// break;
// case "user":
// result.Username = v.ToString();
// break;
// case "password":
// result.Password = v.ToString();
// break;
// case "connect_timeout":
// result.Timeout = int.Parse(v);
// break;
// case "application_name":
// result.ApplicationName = v.ToString();
// break;
// case "options":
// result.Options = v.ToString();
// break;
// case "sslmode":
// result.SslMode = ToSslMode(v);
// break;
// default:
// // Todo what do we do with values we do not support/recognize?
// break;
//}
}
private SslMode ToSslMode(ReadOnlySpan<char> v)
=> v switch
{
"disable" => SslMode.Disable,
"allow" => SslMode.Allow,
"prefer" => SslMode.Prefer,
"require" => SslMode.Require,
"verify-ca" => SslMode.VerifyCA,
"verify-full" => SslMode.VerifyFull,
_ => throw new ArgumentException("Not a valid SSL mode"),
};
}