-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ba24d3
commit 2e4c7c1
Showing
13 changed files
with
72 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using SQLite; | ||
|
||
namespace Hyperstellar.Sql; | ||
|
||
[Table("Alias")] | ||
public sealed class CocAlias(string alias, string cocId) : DbObj<CocAlias> | ||
{ | ||
private string _alias = alias.ToLower(); | ||
|
||
[PrimaryKey, NotNull] | ||
public string Alias | ||
{ | ||
get => _alias; | ||
set => _alias = value.ToLower(); | ||
} | ||
|
||
[NotNull] | ||
public string CocId { get; set; } = cocId; | ||
|
||
public CocAlias() : this("", "") { } | ||
|
||
internal static CocAlias? TryFetch(string alias) | ||
{ | ||
alias = alias.ToLower(); | ||
return FetchAll().FirstOrDefault(a => a.Alias == alias); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,38 @@ | ||
using System.Collections; | ||
using SQLite; | ||
|
||
namespace Hyperstellar.Sql; | ||
|
||
internal static class Db | ||
public abstract class Db | ||
{ | ||
internal static readonly SQLiteConnection s_db = DbObj.s_db; | ||
private protected static readonly SQLiteConnection s_db = new("Hyperstellar.db"); | ||
|
||
internal static Main? GetMainByDiscord(ulong uid) => s_db.Table<Main>().FirstOrDefault(m => m.Discord == uid); | ||
|
||
internal static IEnumerable<Main> GetDonations() => s_db.Table<Main>(); | ||
|
||
internal static bool UpdateMain(Main main) => s_db.Update(main) == 1; | ||
|
||
internal static CocMemberAlias? TryGetAlias(string alias) | ||
internal static void Commit() | ||
{ | ||
alias = alias.ToLower(); | ||
return s_db.Table<CocMemberAlias>().FirstOrDefault(a => a.Alias == alias); | ||
s_db.Commit(); | ||
s_db.BeginTransaction(); | ||
} | ||
|
||
internal static IEnumerable<CocMemberAlias> GetAliases() => s_db.Table<CocMemberAlias>(); | ||
internal static int InsertAll(IEnumerable objects) => s_db.InsertAll(objects); | ||
|
||
internal static bool AddAlias(string alias, Member member) | ||
internal static async Task InitAsync() | ||
{ | ||
CocMemberAlias cocMemberAlias = new(alias.ToLower(), member.CocId); | ||
int count = s_db.Insert(cocMemberAlias); | ||
return count == 1; | ||
s_db.BeginTransaction(); | ||
await Program.TryUntilAsync(async () => | ||
{ | ||
await Task.Delay(5 * 60 * 1000); | ||
Commit(); | ||
}, runForever: true); | ||
} | ||
|
||
internal virtual int Insert() => s_db.Insert(this); | ||
|
||
internal int Delete() => s_db.Delete(this); | ||
|
||
internal int Update() => s_db.Update(this); | ||
} | ||
|
||
public abstract class DbObj<T> : Db where T : DbObj<T>, new() | ||
{ | ||
internal static TableQuery<T> FetchAll() => s_db.Table<T>(); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters