mirror of
https://github.com/zoriya/Kyoo.git
synced 2026-05-31 03:15:16 -04:00
Allow random queries to be paginated
This commit is contained in:
@@ -41,6 +41,13 @@ namespace Kyoo.Postgresql
|
||||
/// </remarks>
|
||||
public abstract class DatabaseContext : DbContext
|
||||
{
|
||||
/// <summary>
|
||||
/// Calculate the MD5 of a string, can only be used in database context.
|
||||
/// </summary>
|
||||
/// <param name="str">The string to hash</param>
|
||||
/// <returns>The hash</returns>
|
||||
public static string MD5(string str) => throw new NotSupportedException();
|
||||
|
||||
/// <summary>
|
||||
/// All collections of Kyoo. See <see cref="Collection"/>.
|
||||
/// </summary>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
<PropertyGroup>
|
||||
<AssemblyName>Kyoo.Postgresql</AssemblyName>
|
||||
<RootNamespace>Kyoo.Postgresql</RootNamespace>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -18,12 +18,14 @@
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using EFCore.NamingConventions.Internal;
|
||||
using Kyoo.Abstractions.Models;
|
||||
using Kyoo.Utils;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
|
||||
using Npgsql;
|
||||
|
||||
namespace Kyoo.Postgresql
|
||||
@@ -104,6 +106,18 @@ namespace Kyoo.Postgresql
|
||||
modelBuilder.HasPostgresEnum<Genre>();
|
||||
modelBuilder.HasPostgresEnum<ItemKind>();
|
||||
|
||||
modelBuilder.HasDbFunction(typeof(DatabaseContext).GetMethod(nameof(MD5)))
|
||||
.HasTranslation(args =>
|
||||
new SqlFunctionExpression(
|
||||
"md5",
|
||||
args,
|
||||
nullable: true,
|
||||
argumentsPropagateNullability: new[] { false },
|
||||
type: args[0].Type,
|
||||
typeMapping: args[0].TypeMapping
|
||||
)
|
||||
);
|
||||
|
||||
base.OnModelCreating(modelBuilder);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user