AppDbContext: Add ExecuteEmbeddedScript()
This commit is contained in:
@ -10,6 +10,7 @@ using Microsoft.Data.Sqlite;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Collections.Generic;
|
||||
using Elwig.Models.Dtos;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Elwig.Helpers {
|
||||
|
||||
@ -106,6 +107,12 @@ namespace Elwig.Helpers {
|
||||
await (await cmd.ExecuteReaderAsync()).CloseAsync();
|
||||
}
|
||||
|
||||
public static async Task ExecuteEmbeddedScript(SqliteConnection cnx, Assembly asm, string name) {
|
||||
using var stream = asm.GetManifestResourceStream(name) ?? throw new FileNotFoundException("Unable to load embedded resource");
|
||||
using var reader = new StreamReader(stream);
|
||||
await ExecuteBatch(cnx, await reader.ReadToEndAsync());
|
||||
}
|
||||
|
||||
public static async Task<object?> ExecuteScalar(SqliteConnection cnx, string sql) {
|
||||
using var cmd = cnx.CreateCommand();
|
||||
cmd.CommandText = sql;
|
||||
|
Reference in New Issue
Block a user