Added SQLite storage backend.

This commit is contained in:
flash 2025-04-27 22:31:35 +00:00
commit 3f6007922c
Signed by: flash
GPG key ID: 2C9C2C574D47FE3E
21 changed files with 665 additions and 245 deletions
SharpChat

View file

@ -1,9 +1,10 @@
using SharpChat;
using SharpChat.Configuration;
using SharpChat.Messages;
using SharpChat.Flashii;
using System.Text;
using SharpChat.MariaDB;
using SharpChat.Messages;
using SharpChat.SQLite;
using System.Text;
const string CONFIG = "sharpchat.cfg";
@ -124,18 +125,23 @@ FlashiiClient flashii = new(httpClient, config.ScopeTo("msz"));
if(hasCancelled) return;
MessageStorage msgStore;
if(string.IsNullOrWhiteSpace(config.SafeReadValue("mariadb:host", string.Empty))) {
msgStore = new VirtualMessageStorage();
} else {
MariaDBMessageStorage mdbes = new(MariaDBMessageStorage.BuildConnString(config.ScopeTo("mariadb")));
msgStore = mdbes;
await mdbes.RunMigrations();
Storage storage = string.IsNullOrWhiteSpace(config.SafeReadValue("mariadb:host", string.Empty))
? new SQLiteStorage(SQLiteStorage.BuildConnectionString(config.ScopeTo("sqlite")))
: new MariaDBStorage(MariaDBStorage.BuildConnectionString(config.ScopeTo("mariadb")));
try {
if(hasCancelled) return;
await storage.UpgradeStorage();
if(hasCancelled) return;
using SockChatServer scs = new(flashii, flashii, storage.CreateMessageStorage(), config.ScopeTo("chat"));
scs.Listen(mre);
mre.WaitOne();
} finally {
if(storage is IDisposable disp)
disp.Dispose();
}
if(hasCancelled) return;
using SockChatServer scs = new(flashii, flashii, msgStore, config.ScopeTo("chat"));
scs.Listen(mre);
mre.WaitOne();