2016-12-16 14:18:37 +01:00
|
|
|
|
using System;
|
2020-03-28 15:13:50 +01:00
|
|
|
|
using Umbraco.Core.Persistence.Dtos;
|
2020-11-10 08:50:47 +00:00
|
|
|
|
using Umbraco.Core.Runtime;
|
2016-12-16 14:18:37 +01:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Core.Persistence
|
|
|
|
|
|
{
|
|
|
|
|
|
internal static class UmbracoDatabaseExtensions
|
|
|
|
|
|
{
|
|
|
|
|
|
public static UmbracoDatabase AsUmbracoDatabase(this IUmbracoDatabase database)
|
|
|
|
|
|
{
|
|
|
|
|
|
var asDatabase = database as UmbracoDatabase;
|
|
|
|
|
|
if (asDatabase == null) throw new Exception("oops: database.");
|
|
|
|
|
|
return asDatabase;
|
|
|
|
|
|
}
|
2020-03-28 15:13:50 +01:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets a key/value directly from the database, no scope, nothing.
|
|
|
|
|
|
/// </summary>
|
2020-11-10 08:50:47 +00:00
|
|
|
|
/// <remarks>Used by <see cref="CoreRuntimeBootstrapper"/> to determine the runtime state.</remarks>
|
2020-03-28 15:13:50 +01:00
|
|
|
|
public static string GetFromKeyValueTable(this IUmbracoDatabase database, string key)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (database is null) return null;
|
|
|
|
|
|
|
|
|
|
|
|
var sql = database.SqlContext.Sql()
|
|
|
|
|
|
.Select<KeyValueDto>()
|
|
|
|
|
|
.From<KeyValueDto>()
|
|
|
|
|
|
.Where<KeyValueDto>(x => x.Key == key);
|
|
|
|
|
|
return database.FirstOrDefault<KeyValueDto>(sql)?.Value;
|
|
|
|
|
|
}
|
2016-12-16 14:18:37 +01:00
|
|
|
|
}
|
2017-07-20 11:21:28 +02:00
|
|
|
|
}
|