Cut RethinkDB
Remove the vendored RethinkDb driver and its Linq provider, the Rethink backing store, the already-stubbed RethinkConnection, the Rethink test window, and the Rethink-only Remotion.Linq and Logging.Abstractions DLLs. The database editor now works only on GameData/AetherDB.msgpack, with a Save button replacing the dead Connect UI and broken JSON export. RethinkTable becomes DatabaseCategory, which only groups editor entries. Economy.Server still references Rethink; it was already unbuildable and is handled separately. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
086b966c30
commit
f568a7d14f
683 changed files with 26 additions and 49854 deletions
|
|
@ -5,7 +5,6 @@
|
|||
"MessagePack",
|
||||
"Unity.Mathematics",
|
||||
"UniRx",
|
||||
"RethinkDB",
|
||||
"Ink"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ using MessagePack;
|
|||
using Newtonsoft.Json;
|
||||
using Unity.Mathematics;
|
||||
|
||||
[RethinkTable("Galaxy"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
[DatabaseCategory("Galaxy"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class Faction : DatabaseEntry, INamedEntry
|
||||
{
|
||||
[Inspectable, JsonProperty("name"), Key(1)]
|
||||
|
|
|
|||
|
|
@ -107,13 +107,13 @@ public class TooltipAttribute : Attribute
|
|||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class RethinkTableAttribute : Attribute
|
||||
public class DatabaseCategoryAttribute : Attribute
|
||||
{
|
||||
public string TableName;
|
||||
public string Category;
|
||||
|
||||
public RethinkTableAttribute(string tableName)
|
||||
public DatabaseCategoryAttribute(string category)
|
||||
{
|
||||
TableName = tableName;
|
||||
Category = category;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,8 +13,6 @@ using System.Text;
|
|||
using System.Threading.Tasks;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
using RethinkDb.Driver;
|
||||
using RethinkDb.Driver.Net;
|
||||
using UniRx;
|
||||
|
||||
public class CultCache
|
||||
|
|
@ -452,123 +450,3 @@ public class SingleFileJsonBackingStore : SingleFileBackingStore
|
|||
return JsonConvert.DeserializeObject<DatabaseEntry[]>(Encoding.UTF8.GetString(data));
|
||||
}
|
||||
}
|
||||
|
||||
public class RethinkBackingStore : CacheBackingStore, RealtimeBackingStore
|
||||
{
|
||||
public const string DEFAULT_TABLE = "Default";
|
||||
public static RethinkDB R = RethinkDB.R;
|
||||
public string DatabaseName { get; }
|
||||
public string ConnectionString { get; }
|
||||
|
||||
private string[] _syncTables;
|
||||
private Connection _connection;
|
||||
private Dictionary<DatabaseEntry, string> _entryHashes = new Dictionary<DatabaseEntry, string>();
|
||||
|
||||
public void ObserveChanges()
|
||||
{
|
||||
foreach (var table in _syncTables)
|
||||
{
|
||||
// Subscribe to changes from RethinkDB
|
||||
Task.Run(async () =>
|
||||
{
|
||||
var result = await R
|
||||
.Db(DatabaseName)
|
||||
.Table(table)
|
||||
.Changes()
|
||||
.RunChangesAsync<DatabaseEntry>(_connection);
|
||||
while (await result.MoveNextAsync())
|
||||
{
|
||||
var change = result.Current;
|
||||
if(change.NewValue==null)
|
||||
EntryDeleted.OnNext(change.OldValue);
|
||||
else if(change.OldValue==null)
|
||||
EntryAdded.OnNext(change.NewValue);
|
||||
else EntryUpdated.OnNext(change.NewValue);
|
||||
}
|
||||
}).WrapAwait();
|
||||
}
|
||||
}
|
||||
|
||||
public RethinkBackingStore(string databaseName, string connectionString)
|
||||
{
|
||||
DatabaseName = databaseName;
|
||||
ConnectionString = connectionString;
|
||||
|
||||
RegisterResolver.Register();
|
||||
|
||||
var connectionStringDomainLength = connectionString.IndexOf(':');
|
||||
if (connectionStringDomainLength < 1)
|
||||
throw new ArgumentException("Illegal Connection String: must include port!");
|
||||
|
||||
var portString = connectionString.Substring(connectionStringDomainLength + 1);
|
||||
if (!int.TryParse(portString, out var port))
|
||||
throw new ArgumentException($"Illegal connection string! \"{portString}\" is not a valid port number!");
|
||||
|
||||
_connection = R.Connection()
|
||||
.Hostname(connectionString.Substring(0,connectionStringDomainLength))
|
||||
.Port(port).Timeout(60).Connect();
|
||||
|
||||
var tables = R.Db(DatabaseName).TableList().RunAtom<string[]>(_connection);
|
||||
|
||||
_syncTables = typeof(DatabaseEntry).GetAllChildClasses()
|
||||
.Select(t => t.GetCustomAttribute<RethinkTableAttribute>()?.TableName ?? DEFAULT_TABLE).Distinct().ToArray();
|
||||
|
||||
foreach (var st in _syncTables.Where(st => !tables.Contains(st)))
|
||||
R.Db(DatabaseName).TableCreate(st).RunNoReply(_connection);
|
||||
}
|
||||
|
||||
public override void PullAll()
|
||||
{
|
||||
foreach (var table in _syncTables)
|
||||
{
|
||||
// Get entries from RethinkDB
|
||||
Task.Run(async () =>
|
||||
{
|
||||
var result = await R
|
||||
.Db(DatabaseName)
|
||||
.Table(table)
|
||||
.RunCursorAsync<DatabaseEntry>(_connection);
|
||||
|
||||
while (await result.MoveNextAsync())
|
||||
{
|
||||
var entry = result.Current;
|
||||
EntryAdded.OnNext(entry);
|
||||
}
|
||||
}).WrapAwait();
|
||||
}
|
||||
}
|
||||
|
||||
public override async void Push(DatabaseEntry entry)
|
||||
{
|
||||
var type = entry.GetType();
|
||||
//(Entries.ContainsKey(entry.ID) ? EntryUpdated : EntryAdded).OnNext(entry);
|
||||
var table = type.GetCustomAttribute<RethinkTableAttribute>()?.TableName ?? DEFAULT_TABLE;
|
||||
var result = await R
|
||||
.Db(DatabaseName)
|
||||
.Table(table)
|
||||
.Get(entry.ID)
|
||||
.Replace(entry)
|
||||
.RunAsync(_connection);
|
||||
}
|
||||
|
||||
public override async void Delete(DatabaseEntry entry)
|
||||
{
|
||||
if(Entries.ContainsKey(entry.ID))
|
||||
{
|
||||
var type = entry.GetType();
|
||||
var table = type.GetCustomAttribute<RethinkTableAttribute>()?.TableName ?? DEFAULT_TABLE;
|
||||
var result = await R
|
||||
.Db(DatabaseName)
|
||||
.Table(table)
|
||||
.Get(entry.ID)
|
||||
.Delete()
|
||||
.RunAsync(_connection);
|
||||
}
|
||||
}
|
||||
|
||||
public override void PushAll(bool soft = false)
|
||||
{
|
||||
foreach(var entry in Entries.Values)
|
||||
Push(entry);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using RethinkDb.Driver;
|
||||
using RethinkDb.Driver.Ast;
|
||||
using RethinkDb.Driver.Net;
|
||||
|
||||
public static class RethinkConnection
|
||||
{
|
||||
public static RethinkDB R = RethinkDB.R;
|
||||
|
||||
public static RethinkQueryStatus RethinkConnect(CultCache cache, string connectionString, string dbName, bool syncLocalChanges = true)
|
||||
{
|
||||
var status = new RethinkQueryStatus();
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class RethinkQueryStatus
|
||||
{
|
||||
public int RetrievedEntries;
|
||||
public int TotalEntries;
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a8fce60db4f3e614c8d19c3da4cede0e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -4,7 +4,6 @@ using MessagePack;
|
|||
using MessagePack.ReactivePropertyExtension;
|
||||
using MessagePack.Resolvers;
|
||||
using Newtonsoft.Json;
|
||||
using RethinkDb.Driver.Net;
|
||||
|
||||
public static class RegisterResolver
|
||||
{
|
||||
|
|
@ -29,11 +28,7 @@ public static class RegisterResolver
|
|||
{
|
||||
Converters = new List<JsonConverter>
|
||||
{
|
||||
new MathJsonConverter(),
|
||||
Converter.DateTimeConverter,
|
||||
Converter.BinaryConverter,
|
||||
Converter.GroupingConverter,
|
||||
Converter.PocoExprConverter
|
||||
new MathJsonConverter()
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ using static Unity.Mathematics.math;
|
|||
using static Unity.Mathematics.noise;
|
||||
using static NoiseFbm;
|
||||
|
||||
[Inspectable, Serializable, RethinkTable("Galaxy"), MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
[Inspectable, Serializable, DatabaseCategory("Galaxy"), MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class GalaxyMapLayerData : DatabaseEntry, INamedEntry
|
||||
{
|
||||
[Inspectable, JsonProperty("coreBoost"), Key(1)]
|
||||
|
|
|
|||
|
|
@ -304,7 +304,7 @@ public abstract class ItemData : DatabaseEntry, INamedEntry
|
|||
|
||||
}
|
||||
|
||||
[RethinkTable("Items"), Inspectable, MessagePackObject]
|
||||
[DatabaseCategory("Items"), Inspectable, MessagePackObject]
|
||||
public class SimpleCommodityData : ItemData
|
||||
{
|
||||
// // Types of body where this resource can be found
|
||||
|
|
@ -337,7 +337,7 @@ public abstract class CraftedItemData : ItemData
|
|||
// public float IngredientQualityWeight = .5f;
|
||||
}
|
||||
|
||||
[RethinkTable("Items"), Inspectable, MessagePackObject]
|
||||
[DatabaseCategory("Items"), Inspectable, MessagePackObject]
|
||||
public class CompoundCommodityData : CraftedItemData
|
||||
{
|
||||
[InspectableDatabaseLink(typeof(PersonalityAttribute)), JsonProperty("demandProfile"), Key(10)]
|
||||
|
|
@ -347,7 +347,7 @@ public class CompoundCommodityData : CraftedItemData
|
|||
public CompoundCommodityCategory Category;
|
||||
}
|
||||
|
||||
[RethinkTable("Items"), Inspectable, MessagePackObject]
|
||||
[DatabaseCategory("Items"), Inspectable, MessagePackObject]
|
||||
public class ConsumableItemData : CraftedItemData
|
||||
{
|
||||
[Inspectable, JsonProperty("behaviors"), Key(10)]
|
||||
|
|
@ -456,7 +456,7 @@ public class AudioStat
|
|||
public PerformanceStat Stat = new PerformanceStat();
|
||||
}
|
||||
|
||||
[RethinkTable("Items"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
[DatabaseCategory("Items"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class GearData : EquippableItemData
|
||||
{
|
||||
[Inspectable, JsonProperty("hardpointType"), Key(23)]
|
||||
|
|
@ -465,7 +465,7 @@ public class GearData : EquippableItemData
|
|||
[IgnoreMember] public override HardpointType HardpointType => Hardpoint;
|
||||
}
|
||||
|
||||
[RethinkTable("Items"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
[DatabaseCategory("Items"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class CargoBayData : EquippableItemData
|
||||
{
|
||||
[Inspectable, JsonProperty("interiorShape"), Key(24)]
|
||||
|
|
@ -474,14 +474,14 @@ public class CargoBayData : EquippableItemData
|
|||
[IgnoreMember] public override HardpointType HardpointType => HardpointType.Tool;
|
||||
}
|
||||
|
||||
[RethinkTable("Items"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
[DatabaseCategory("Items"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class DockingBayData : CargoBayData
|
||||
{
|
||||
[Inspectable, JsonProperty("maxSize"), Key(25)]
|
||||
public int2 MaxSize;
|
||||
}
|
||||
|
||||
[RethinkTable("Items"), MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
[DatabaseCategory("Items"), MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class WeaponItemData : GearData
|
||||
{
|
||||
[Inspectable, JsonProperty("range"), Key(24)]
|
||||
|
|
@ -500,7 +500,7 @@ public class WeaponItemData : GearData
|
|||
public WeaponModifiers WeaponModifiers;
|
||||
}
|
||||
|
||||
[RethinkTable("Items"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
[DatabaseCategory("Items"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class HullData : EquippableItemData
|
||||
{
|
||||
[Inspectable, JsonProperty("hardpoints"), Key(23)]
|
||||
|
|
@ -630,7 +630,7 @@ public class PerformanceStat
|
|||
}
|
||||
}
|
||||
|
||||
[RethinkTable("Items"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
[DatabaseCategory("Items"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class PersonalityAttribute : DatabaseEntry, INamedEntry
|
||||
{
|
||||
[Inspectable, JsonProperty("name"), Key(1)]
|
||||
|
|
|
|||
|
|
@ -1,8 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9af1bb2d775b93c40b0cc7f40a6a2a54
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
{
|
||||
"name": "RethinkDB"
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b2a4424e75e7709478154ddd9db0b344
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a63fc00275e79cc43ac526c37980469d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d5afeae59c88f504a9a6416494369a31
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
using System;
|
||||
|
||||
namespace RethinkDb.Driver.Linq.Attributes
|
||||
{
|
||||
public class PrimaryIndexAttribute : Attribute
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1546d1a62ca72f14281d41cfb0b190b4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
using System;
|
||||
|
||||
namespace RethinkDb.Driver.Linq.Attributes
|
||||
{
|
||||
public class SecondaryIndexAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 70880667ec2520243b121b4452e01fab
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
using Remotion.Linq;
|
||||
using Remotion.Linq.Parsing.Structure;
|
||||
using RethinkDb.Driver.Ast;
|
||||
using RethinkDb.Driver.Net;
|
||||
|
||||
namespace RethinkDb.Driver.Linq
|
||||
{
|
||||
public static class LinqExtensions
|
||||
{
|
||||
public static RethinkQueryable<T> AsQueryable<T>( this Table term, IConnection conn )
|
||||
{
|
||||
var executor = new RethinkQueryExecutor( term, conn );
|
||||
return new RethinkQueryable<T>(
|
||||
new DefaultQueryProvider(
|
||||
typeof( RethinkQueryable<> ),
|
||||
QueryParser.CreateDefault(),
|
||||
executor )
|
||||
);
|
||||
}
|
||||
|
||||
public static RethinkQueryable<T> Table<T>( this Db db, string tableName, IConnection conn )
|
||||
{
|
||||
return db.Table( tableName ).AsQueryable<T>( conn );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 497b6d9e1e2415d448096fe5e67c4d2f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using Remotion.Linq.Clauses.Expressions;
|
||||
using RethinkDb.Driver.Ast;
|
||||
using RethinkDb.Driver.Linq.WhereClauseParsers.SubQueryVisitor;
|
||||
using RethinkDb.Driver.Utils;
|
||||
|
||||
namespace RethinkDb.Driver.Linq
|
||||
{
|
||||
public class MemberNameResolver
|
||||
{
|
||||
private readonly MemberExpression _expression;
|
||||
|
||||
public MemberNameResolver( MemberExpression expression )
|
||||
{
|
||||
_expression = expression;
|
||||
}
|
||||
|
||||
public ReqlExpr Resolve( ReqlExpr reqlExpr ) => ResolveMemberExpression( reqlExpr, _expression );
|
||||
|
||||
private static ReqlExpr ResolveMemberExpression( ReqlExpr reqlExpr, MemberExpression expression )
|
||||
{
|
||||
if( expression.Expression.NodeType == ExpressionType.MemberAccess )
|
||||
reqlExpr = ResolveMemberExpression( reqlExpr, (MemberExpression)expression.Expression );
|
||||
if( expression.Expression.NodeType == ExpressionType.Extension && expression.Expression is SubQueryExpression )
|
||||
reqlExpr = ResolveExtensionExpression( reqlExpr, (SubQueryExpression)expression.Expression );
|
||||
return reqlExpr[QueryHelper.GetJsonMemberName( expression.Member )];
|
||||
}
|
||||
|
||||
private static ReqlExpr ResolveExtensionExpression( ReqlExpr reqlExpr, SubQueryExpression expression )
|
||||
{
|
||||
var subQueryVisitors = new List<ISubQueryVisitor>
|
||||
{
|
||||
new AnySubQueryVisitor(),
|
||||
new AllSubQueryVisitor(),
|
||||
new FirstAndLastSubQueryVisitor()
|
||||
};
|
||||
|
||||
var subQueryVisitor = subQueryVisitors.FirstOrDefault( x => x.CanVisit( expression.QueryModel ) );
|
||||
|
||||
if( subQueryVisitor == null )
|
||||
throw new NotSupportedException( "subqueries not allowed ." );
|
||||
|
||||
return subQueryVisitor.Visit( reqlExpr, expression.QueryModel );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d6d58b735ecbbe44da23bc61faede0f3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<Description>An experimental LINQ to ReQL provider for the RethinkDB C# Driver.</Description>
|
||||
<PackageReleaseNotes>
|
||||
</PackageReleaseNotes>
|
||||
<Version>0.0.0-localbuild</Version>
|
||||
<Authors>Brian Chavez;jrote1</Authors>
|
||||
<TargetFrameworks>net45;netstandard2.0</TargetFrameworks>
|
||||
<CodeAnalysisRuleSet>RethinkDb.Driver.Linq.ruleset</CodeAnalysisRuleSet>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<AssemblyOriginatorKeyFile>
|
||||
</AssemblyOriginatorKeyFile>
|
||||
<SignAssembly>false</SignAssembly>
|
||||
<AssemblyName>RethinkDb.Driver.Linq</AssemblyName>
|
||||
<PackageTags>rethinkdb;document;database;driver;reql;linq;nosql</PackageTags>
|
||||
<PackageIconUrl>https://raw.githubusercontent.com/wiki/bchavez/RethinkDb.Driver/logo.png</PackageIconUrl>
|
||||
<PackageProjectUrl>https://github.com/bchavez/RethinkDb.Driver</PackageProjectUrl>
|
||||
<PackageLicenseUrl>https://raw.githubusercontent.com/bchavez/RethinkDb.Driver/master/LICENSE</PackageLicenseUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<RepositoryUrl>https://github.com/bchavez/RethinkDb.Driver</RepositoryUrl>
|
||||
<!--Source Link Settings-->
|
||||
<PublishRepositoryUrl>true</PublishRepositoryUrl>
|
||||
<EmbedUntrackedSources>false</EmbedUntrackedSources>
|
||||
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
|
||||
<DefineConstants>$(DefineConstants);STANDARD</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\RethinkDb.Driver\RethinkDb.Driver.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Remotion.Linq" Version="2.1.1" />
|
||||
<PackageReference Include="Roslynator.Analyzers" Version="1.5.0" PrivateAssets="All" />
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta-63127-02" PrivateAssets="All" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
|
||||
<PackageReference Include="Common.Logging" Version="3.3.0" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ccd26d30308e3de449c758dc41125bbc
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RuleSet Name="Default" Description="Default" ToolsVersion="14.0">
|
||||
<Rules AnalyzerId="Roslynator.CSharp.Analyzers" RuleNamespace="Roslynator.CSharp.Analyzers">
|
||||
<Rule Id="RCS1090" Action="Error" />
|
||||
</Rules>
|
||||
</RuleSet>
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4a29586679b0ef3489a21ca519dd6c41
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace RethinkDb.Driver.Linq
|
||||
{
|
||||
public class RethinkDbGroup<T, TVal> : IGrouping<T, TVal>
|
||||
{
|
||||
public IEnumerator<TVal> GetEnumerator()
|
||||
{
|
||||
return Reduction.GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
public T Key { get; set; }
|
||||
|
||||
public List<TVal> Reduction { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f4dc1e08321f5894cbc97d340d1077c3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,190 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using Remotion.Linq;
|
||||
using Remotion.Linq.Clauses;
|
||||
using Remotion.Linq.Clauses.Expressions;
|
||||
using Remotion.Linq.Clauses.ResultOperators;
|
||||
using RethinkDb.Driver.Ast;
|
||||
using RethinkDb.Driver.Linq.Attributes;
|
||||
using RethinkDb.Driver.Linq.WhereClauseParsers;
|
||||
using ExpressionVisitor = RethinkDb.Driver.Linq.WhereClauseParsers.ExpressionVisitor;
|
||||
using RethinkDb.Driver.Utils;
|
||||
|
||||
namespace RethinkDb.Driver.Linq
|
||||
{
|
||||
public class RethinkDbQueryModelVisitor : QueryModelVisitorBase
|
||||
{
|
||||
private readonly Table _table;
|
||||
|
||||
public ReqlAst Query => Stack.Peek();
|
||||
public Stack<ReqlExpr> Stack = new Stack<ReqlExpr>();
|
||||
|
||||
public RethinkDbQueryModelVisitor( Table table )
|
||||
{
|
||||
_table = table;
|
||||
}
|
||||
|
||||
public override void VisitQueryModel( QueryModel queryModel )
|
||||
{
|
||||
Stack.Push( _table );
|
||||
base.VisitQueryModel( queryModel );
|
||||
}
|
||||
|
||||
public override void VisitMainFromClause( MainFromClause fromClause, QueryModel queryModel )
|
||||
{
|
||||
var subQuery = fromClause.FromExpression as SubQueryExpression;
|
||||
if( subQuery != null )
|
||||
{
|
||||
var query = subQuery.QueryModel;
|
||||
VisitBodyClauses( query.BodyClauses, query );
|
||||
base.VisitMainFromClause( fromClause, queryModel );
|
||||
}
|
||||
|
||||
base.VisitMainFromClause( fromClause, queryModel );
|
||||
}
|
||||
|
||||
public override void VisitWhereClause( WhereClause whereClause, QueryModel queryModel, int index )
|
||||
{
|
||||
var expressions = SplitWhereClause( whereClause.Predicate );
|
||||
|
||||
foreach( var expression in expressions.ToList() )
|
||||
{
|
||||
var whereClauseParsers = new List<IWhereClauseParser>
|
||||
{
|
||||
new GroupItemsParser(),
|
||||
new PrimaryIndexParser(),
|
||||
new SecondaryIndexParser(),
|
||||
new DefaultParser()
|
||||
};
|
||||
|
||||
var reql = Stack.Pop();
|
||||
var matchingParser = whereClauseParsers.FirstOrDefault( x => x.IsAppropriate( reql, expression, queryModel.ResultTypeOverride ) );
|
||||
if( matchingParser != null )
|
||||
Stack.Push( matchingParser.Parse( reql, queryModel, expression ) );
|
||||
else
|
||||
throw new NotSupportedException( "Unable to vist Where clause" );
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<Expression> SplitWhereClause( Expression predicate )
|
||||
{
|
||||
if( predicate.NodeType != ExpressionType.AndAlso )
|
||||
{
|
||||
yield return predicate;
|
||||
yield break;
|
||||
}
|
||||
|
||||
var binaryExpression = predicate as BinaryExpression;
|
||||
if( binaryExpression == null )
|
||||
yield break;
|
||||
|
||||
|
||||
foreach( var expression in SplitWhereClause( binaryExpression.Left ) )
|
||||
yield return expression;
|
||||
yield return binaryExpression.Right;
|
||||
}
|
||||
|
||||
private static ReqlExpr GetSelectReqlAst( Expression selector )
|
||||
{
|
||||
var visitor = new SelectionProjector();
|
||||
visitor.Visit( selector );
|
||||
return visitor.Current;
|
||||
}
|
||||
|
||||
public override void VisitOrderByClause( OrderByClause orderByClause, QueryModel queryModel, int index )
|
||||
{
|
||||
var expression = orderByClause.Orderings[0].Expression as MemberExpression;
|
||||
if( expression == null )
|
||||
return;
|
||||
|
||||
OrderBy reql;
|
||||
var currentStack = Stack.Pop();
|
||||
var memberName = QueryHelper.GetJsonMemberName( expression.Member );
|
||||
if( orderByClause.Orderings[0].OrderingDirection == OrderingDirection.Asc )
|
||||
reql = currentStack.OrderBy( memberName );
|
||||
else
|
||||
reql = currentStack.OrderBy( RethinkDB.R.Desc( memberName ) );
|
||||
|
||||
if( currentStack is Table && expression.Member.CustomAttributes.Any( x => x.AttributeType == typeof( PrimaryIndexAttribute ) || x.AttributeType == typeof( SecondaryIndexAttribute ) ) )
|
||||
reql = reql.OptArg( "index", memberName );
|
||||
|
||||
Stack.Push( reql );
|
||||
}
|
||||
|
||||
public override void VisitSelectClause( SelectClause selectClause, QueryModel queryModel )
|
||||
{
|
||||
if( queryModel.ResultOperators.FirstOrDefault() is AverageResultOperator )
|
||||
{
|
||||
var memberExpression = selectClause.Selector as MemberExpression;
|
||||
var memberNameResolver = new MemberNameResolver( memberExpression );
|
||||
Stack.Push( Stack.Pop().Avg( x => memberNameResolver.Resolve( x ) ) );
|
||||
return;
|
||||
}
|
||||
|
||||
if( queryModel.ResultOperators.FirstOrDefault() is CountResultOperator )
|
||||
{
|
||||
Stack.Push( Stack.Pop().Count( ) );
|
||||
return;
|
||||
}
|
||||
|
||||
var expr = GetSelectReqlAst( selectClause.Selector );
|
||||
if( !ReferenceEquals( expr, null ) )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
base.VisitSelectClause( selectClause, queryModel );
|
||||
}
|
||||
|
||||
protected override void VisitBodyClauses( ObservableCollection<IBodyClause> bodyClauses, QueryModel queryModel )
|
||||
{
|
||||
if( queryModel.ResultTypeOverride.GetTypeInfo().IsGenericTypeDefinition && queryModel.ResultTypeOverride.GetGenericArguments()[0].GetGenericTypeDefinition() != typeof( IGrouping<,> ) )
|
||||
{
|
||||
base.VisitBodyClauses( bodyClauses, queryModel );
|
||||
return;
|
||||
}
|
||||
|
||||
var group = queryModel.ResultOperators.FirstOrDefault() as GroupResultOperator;
|
||||
if( group == null )
|
||||
{
|
||||
base.VisitBodyClauses( bodyClauses, queryModel );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var keySelector = (MemberExpression)group.KeySelector;
|
||||
var groupReql = Stack.Pop().Group( QueryHelper.GetJsonMemberName( keySelector.Member ) );
|
||||
|
||||
var memberAccess = group.ElementSelector as MemberExpression;
|
||||
Stack.Push( memberAccess != null ? groupReql.GetField( QueryHelper.GetJsonMemberName( memberAccess.Member ) ).Ungroup() : groupReql.Ungroup() );
|
||||
}
|
||||
|
||||
public override void VisitResultOperator( ResultOperatorBase resultOperator, QueryModel queryModel, int index )
|
||||
{
|
||||
if( resultOperator is AnyResultOperator )
|
||||
Stack.Push( Stack.Pop().Count() );
|
||||
else if( resultOperator is AllResultOperator )
|
||||
{
|
||||
var allResultOperator = resultOperator as AllResultOperator;
|
||||
Stack.Push( Stack.Pop().Filter( x => GetWhereReqlAst( x, allResultOperator.Predicate ).Not() ).Count() );
|
||||
}
|
||||
else if( resultOperator is FirstResultOperator )
|
||||
Stack.Push( Stack.Pop().Nth( 0 ) );
|
||||
else if( resultOperator is LastResultOperator )
|
||||
Stack.Push( Stack.Pop().Nth( -1 ) );
|
||||
|
||||
base.VisitResultOperator( resultOperator, queryModel, index );
|
||||
}
|
||||
|
||||
private static ReqlExpr GetWhereReqlAst( ReqlExpr reqlExpr, Expression predicate )
|
||||
{
|
||||
var visitor = new ExpressionVisitor( reqlExpr, typeof( bool ) );
|
||||
visitor.Visit( predicate );
|
||||
return visitor.Current;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ff262bcd2f16e574686b6a9cbf453bf7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,132 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Remotion.Linq;
|
||||
using Remotion.Linq.Clauses.ResultOperators;
|
||||
using RethinkDb.Driver.Ast;
|
||||
using RethinkDb.Driver.Net;
|
||||
|
||||
namespace RethinkDb.Driver.Linq
|
||||
{
|
||||
public class RethinkQueryExecutor : IQueryExecutor
|
||||
{
|
||||
private readonly Table table;
|
||||
private readonly IConnection connection;
|
||||
|
||||
public RethinkQueryExecutor( Table table, IConnection connection )
|
||||
{
|
||||
this.table = table;
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
protected virtual void ProcessQuery( ReqlAst query )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public T ExecuteScalar<T>( QueryModel queryModel )
|
||||
{
|
||||
var visitor = new RethinkDbQueryModelVisitor( table );
|
||||
|
||||
visitor.VisitQueryModel( queryModel );
|
||||
|
||||
var query = visitor.Query;
|
||||
ProcessQuery( query );
|
||||
|
||||
var result = query.Run( connection );
|
||||
|
||||
if( queryModel.ResultOperators.FirstOrDefault() is AnyResultOperator )
|
||||
return result > 0;
|
||||
if( queryModel.ResultOperators.FirstOrDefault() is AllResultOperator )
|
||||
return result == 0;
|
||||
|
||||
return (T)result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public T ExecuteSingle<T>( QueryModel queryModel, bool returnDefaultWhenEmpty )
|
||||
{
|
||||
var visitor = new RethinkDbQueryModelVisitor( table );
|
||||
|
||||
visitor.VisitQueryModel( queryModel );
|
||||
|
||||
var query = visitor.Query;
|
||||
ProcessQuery( query );
|
||||
|
||||
try
|
||||
{
|
||||
return query.RunResult<T>( connection );
|
||||
}
|
||||
catch( ReqlNonExistenceError ex )
|
||||
{
|
||||
if( ShouldReturnDefault( queryModel ) )
|
||||
return default( T );
|
||||
throw new InvalidOperationException( ex.Message );
|
||||
}
|
||||
}
|
||||
|
||||
private static bool ShouldReturnDefault( QueryModel queryModel )
|
||||
{
|
||||
var firstResultOperator = queryModel.ResultOperators.FirstOrDefault();
|
||||
return ( firstResultOperator as FirstResultOperator )?.ReturnDefaultWhenEmpty
|
||||
?? ( firstResultOperator as LastResultOperator )?.ReturnDefaultWhenEmpty
|
||||
?? false;
|
||||
}
|
||||
|
||||
public IEnumerable<T> ExecuteCollection<T>( QueryModel queryModel )
|
||||
{
|
||||
var visitor = new RethinkDbQueryModelVisitor( table );
|
||||
|
||||
visitor.VisitQueryModel( queryModel );
|
||||
|
||||
var query = visitor.Query;
|
||||
ProcessQuery( query );
|
||||
|
||||
if( typeof(T).GetTypeInfo().IsGenericType && typeof(T).GetGenericTypeDefinition() == typeof(IGrouping<,>) )
|
||||
{
|
||||
|
||||
return typeof(RethinkQueryExecutor)
|
||||
.GetMethod(nameof(DeserializeGrouping),
|
||||
BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly)
|
||||
.MakeGenericMethod(
|
||||
typeof(T).GetGenericArguments()[0],
|
||||
typeof(T).GetGenericArguments()[1])
|
||||
.Invoke(null, new object[]
|
||||
{
|
||||
query.Run(connection) as JArray
|
||||
}) as IEnumerable<T>;
|
||||
}
|
||||
|
||||
if( query is Get )
|
||||
{
|
||||
return new List<T>
|
||||
{
|
||||
query.RunResult<T>(connection)
|
||||
};
|
||||
}
|
||||
|
||||
return query.RunResult<List<T>>( connection );
|
||||
}
|
||||
|
||||
private static List<IGrouping<T, TVal>> DeserializeGrouping<T, TVal>( JArray groups )
|
||||
{
|
||||
var result = new List<IGrouping<T, TVal>>();
|
||||
|
||||
foreach( var group in groups )
|
||||
{
|
||||
var groupArray = (JObject)group;
|
||||
result.Add( new RethinkDbGroup<T, TVal>
|
||||
{
|
||||
Key = groupArray["group"].ToObject<T>(),
|
||||
Reduction = JsonConvert.DeserializeObject<List<TVal>>( groupArray["reduction"].ToString() )
|
||||
} );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 28b39bfa0ac130949b5d48021a4edf10
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using Remotion.Linq;
|
||||
using Remotion.Linq.Parsing.Structure;
|
||||
|
||||
namespace RethinkDb.Driver.Linq
|
||||
{
|
||||
public class RethinkQueryable<T> : QueryableBase<T>
|
||||
{
|
||||
public RethinkQueryable( IQueryParser queryParser, IQueryExecutor executor ) : base( queryParser, executor )
|
||||
{
|
||||
}
|
||||
|
||||
public RethinkQueryable( IQueryProvider provider ) : base( provider )
|
||||
{
|
||||
}
|
||||
|
||||
public RethinkQueryable( IQueryProvider provider, Expression expression ) : base( provider, expression )
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 30f22ad9c416ee6428e4bc7c1aff8cb0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using Remotion.Linq.Clauses.Expressions;
|
||||
using Remotion.Linq.Parsing;
|
||||
using RethinkDb.Driver.Ast;
|
||||
|
||||
namespace RethinkDb.Driver.Linq
|
||||
{
|
||||
public class SelectionProjector : ThrowingExpressionVisitor
|
||||
{
|
||||
private readonly Stack<ReqlExpr> _stack = new Stack<ReqlExpr>();
|
||||
|
||||
public ReqlExpr Current => _stack.Count > 0 ? _stack.Peek() : null;
|
||||
|
||||
protected override Exception CreateUnhandledItemException<T>( T unhandledItem, string visitMethod )
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected override Expression VisitQuerySourceReference( QuerySourceReferenceExpression expression )
|
||||
{
|
||||
return expression;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e51a9e666bbd9484f94c924bb2310d16
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5b588de5b68f5314d9eb711c7e248322
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using Remotion.Linq;
|
||||
using RethinkDb.Driver.Ast;
|
||||
|
||||
namespace RethinkDb.Driver.Linq.WhereClauseParsers
|
||||
{
|
||||
public abstract class BaseIndexParser<T> : IWhereClauseParser
|
||||
{
|
||||
public bool IsAppropriate( ReqlAst reql, Expression expression, Type resultType )
|
||||
{
|
||||
var binaryExpression = expression as BinaryExpression;
|
||||
|
||||
if( !( reql is Table ) || binaryExpression?.NodeType != ExpressionType.Equal )
|
||||
return false;
|
||||
|
||||
var left = binaryExpression.Left as MemberExpression;
|
||||
if( left != null )
|
||||
return IsIndex( left );
|
||||
|
||||
var right = binaryExpression.Right as MemberExpression;
|
||||
|
||||
return right != null && IsIndex( right );
|
||||
}
|
||||
|
||||
private static bool IsIndex( MemberExpression left )
|
||||
{
|
||||
return left.Member.CustomAttributes.Any( x => x.AttributeType == typeof( T ) );
|
||||
}
|
||||
|
||||
public abstract ReqlExpr Parse( ReqlExpr expression, QueryModel queryModel, Expression predicate );
|
||||
|
||||
protected static object GetValue( BinaryExpression binaryExpression )
|
||||
{
|
||||
var left = binaryExpression.Left as ConstantExpression;
|
||||
return left != null ? left.Value : ( (ConstantExpression)binaryExpression.Right ).Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 40d9953e7cea4ff4da4a1a50a3c01de9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
using System;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using Remotion.Linq;
|
||||
using RethinkDb.Driver.Ast;
|
||||
|
||||
namespace RethinkDb.Driver.Linq.WhereClauseParsers
|
||||
{
|
||||
public class DefaultParser : IWhereClauseParser
|
||||
{
|
||||
public bool IsAppropriate( ReqlAst reql, Expression expression, Type resultType ) => true;
|
||||
|
||||
public ReqlExpr Parse( ReqlExpr expression, QueryModel queryModel, Expression predicate )
|
||||
{
|
||||
return expression.Filter( reqlExpr => GetWhereReqlAst( reqlExpr, predicate, queryModel ) );
|
||||
}
|
||||
|
||||
private static ReqlExpr GetWhereReqlAst( ReqlExpr reqlExpr, Expression predicate, QueryModel queryModel )
|
||||
{
|
||||
var visitor = new ExpressionVisitor( reqlExpr, GetResultType( queryModel ) );
|
||||
visitor.Visit( predicate );
|
||||
return visitor.Current;
|
||||
}
|
||||
|
||||
private static Type GetResultType( QueryModel queryModel )
|
||||
{
|
||||
if( !queryModel.ResultTypeOverride.GetTypeInfo().IsGenericType )
|
||||
return queryModel.ResultTypeOverride;
|
||||
return queryModel.ResultTypeOverride.GetTypeInfo().GenericTypeArguments[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 86144ea44b1a9f54d8828051a8230119
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
using System;
|
||||
using System.Linq.Expressions;
|
||||
using RethinkDb.Driver.Ast;
|
||||
|
||||
namespace RethinkDb.Driver.Linq.WhereClauseParsers
|
||||
{
|
||||
public static class ExprHelper
|
||||
{
|
||||
public static ReqlExpr TranslateUnary( ExpressionType type, ReqlExpr term )
|
||||
{
|
||||
switch( type )
|
||||
{
|
||||
case ExpressionType.Not:
|
||||
return term.Not();
|
||||
default:
|
||||
throw new NotSupportedException( "Unary term not supported." );
|
||||
}
|
||||
}
|
||||
|
||||
public static ReqlExpr TranslateBinary( ExpressionType type, ReqlExpr left, ReqlExpr right )
|
||||
{
|
||||
switch( type )
|
||||
{
|
||||
case ExpressionType.Equal:
|
||||
return left.Eq( right );
|
||||
case ExpressionType.NotEqual:
|
||||
return left.Eq( right ).Not();
|
||||
case ExpressionType.LessThan:
|
||||
return left.Lt( right );
|
||||
case ExpressionType.LessThanOrEqual:
|
||||
return left.Le( right );
|
||||
case ExpressionType.GreaterThan:
|
||||
return left.Gt( right );
|
||||
case ExpressionType.GreaterThanOrEqual:
|
||||
return left.Ge( right );
|
||||
case ExpressionType.And:
|
||||
case ExpressionType.AndAlso:
|
||||
return left.And( right );
|
||||
case ExpressionType.Or:
|
||||
case ExpressionType.OrElse:
|
||||
return left.Or( right );
|
||||
case ExpressionType.Not:
|
||||
throw new InvalidOperationException( "ExpresionType:Not cannot be called on a binary translation." );
|
||||
case ExpressionType.Add:
|
||||
return left.Add( right );
|
||||
case ExpressionType.Subtract:
|
||||
return left.Sub( right );
|
||||
case ExpressionType.Multiply:
|
||||
return left.Mul( right );
|
||||
case ExpressionType.Divide:
|
||||
return left.Div( right );
|
||||
case ExpressionType.Modulo:
|
||||
return left.Mod( right );
|
||||
default:
|
||||
throw new NotSupportedException( "Binary expression not supported." );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fc0cb29a01a918646a8592cf88c954f7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,111 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using Remotion.Linq.Clauses.Expressions;
|
||||
using Remotion.Linq.Parsing;
|
||||
using RethinkDb.Driver.Ast;
|
||||
using RethinkDb.Driver.Linq.WhereClauseParsers.SubQueryVisitor;
|
||||
|
||||
namespace RethinkDb.Driver.Linq.WhereClauseParsers
|
||||
{
|
||||
public class ExpressionVisitor : ThrowingExpressionVisitor
|
||||
{
|
||||
private readonly ReqlExpr _reqlExpr;
|
||||
private readonly Type _type;
|
||||
private readonly Stack<ReqlExpr> _stack = new Stack<ReqlExpr>();
|
||||
|
||||
public ExpressionVisitor( ReqlExpr reqlExpr, Type type )
|
||||
{
|
||||
_type = type;
|
||||
_reqlExpr = reqlExpr;
|
||||
}
|
||||
|
||||
public ReqlExpr Current => _stack.Peek();
|
||||
|
||||
protected override Exception CreateUnhandledItemException<T>( T unhandledItem, string visitMethod )
|
||||
{
|
||||
string itemText = unhandledItem.ToString();
|
||||
var message = $"The expression '{itemText}' (type: {typeof( T )}) is not supported by RethinkDB LINQ provider.";
|
||||
return new NotSupportedException( message );
|
||||
}
|
||||
|
||||
private ReqlExpr VistSide( Expression expression )
|
||||
{
|
||||
if( expression.NodeType == ExpressionType.Extension && expression is QuerySourceReferenceExpression )
|
||||
return _reqlExpr;
|
||||
Visit( expression );
|
||||
return _stack.Pop();
|
||||
}
|
||||
|
||||
protected override Expression VisitBinary( BinaryExpression expression )
|
||||
{
|
||||
var left = VistSide( expression.Left );
|
||||
var right = VistSide( expression.Right );
|
||||
|
||||
var operation = ExprHelper.TranslateBinary( expression.NodeType, left, right );
|
||||
_stack.Push( operation );
|
||||
|
||||
return expression;
|
||||
}
|
||||
|
||||
protected override Expression VisitUnary( UnaryExpression expression )
|
||||
{
|
||||
if( expression.NodeType == ExpressionType.Not )
|
||||
{
|
||||
Visit( expression.Operand );
|
||||
_stack.Push( _stack.Pop().Not() );
|
||||
return null;
|
||||
}
|
||||
return base.VisitUnary( expression );
|
||||
}
|
||||
|
||||
protected override Expression VisitConstant( ConstantExpression expression )
|
||||
{
|
||||
var datum = Util.ToReqlExpr( expression.Value );
|
||||
_stack.Push( datum );
|
||||
return expression;
|
||||
}
|
||||
|
||||
protected override Expression VisitMember( MemberExpression expression )
|
||||
{
|
||||
Visit( expression.Expression );
|
||||
|
||||
var fieldName = expression.Member.Name;
|
||||
if( _type.GetTypeInfo().IsGenericType && _type.GetGenericTypeDefinition() == typeof( IGrouping<,> ) && fieldName == "Key" )
|
||||
_stack.Push( _reqlExpr["group"] );
|
||||
else
|
||||
{
|
||||
var memberNameResolver = new MemberNameResolver( expression );
|
||||
_stack.Push( memberNameResolver.Resolve( _reqlExpr ) );
|
||||
}
|
||||
|
||||
return expression;
|
||||
}
|
||||
|
||||
protected override Expression VisitSubQuery( SubQueryExpression expression )
|
||||
{
|
||||
var subQueryVisitors = new List<ISubQueryVisitor>
|
||||
{
|
||||
new AnySubQueryVisitor(),
|
||||
new AllSubQueryVisitor(),
|
||||
new FirstAndLastSubQueryVisitor(),
|
||||
new CountSubQueryVisitor(),
|
||||
new ContainsSubQueryVisitor()
|
||||
};
|
||||
|
||||
var subQueryVisitor = subQueryVisitors.FirstOrDefault( x => x.CanVisit( expression.QueryModel ) );
|
||||
|
||||
if( subQueryVisitor == null ) throw new NotSupportedException( "subqueries not allowed ." );
|
||||
|
||||
_stack.Push( subQueryVisitor.Visit( _reqlExpr, expression.QueryModel ) );
|
||||
return null;
|
||||
}
|
||||
|
||||
protected override Expression VisitQuerySourceReference( QuerySourceReferenceExpression expression )
|
||||
{
|
||||
return expression;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f9875af41ba85e742beeddccd1b460ea
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using Remotion.Linq;
|
||||
using Remotion.Linq.Clauses;
|
||||
using Remotion.Linq.Clauses.Expressions;
|
||||
using Remotion.Linq.Clauses.ResultOperators;
|
||||
using RethinkDb.Driver.Ast;
|
||||
|
||||
namespace RethinkDb.Driver.Linq.WhereClauseParsers
|
||||
{
|
||||
public class GroupItemsParser : IWhereClauseParser
|
||||
{
|
||||
public bool IsAppropriate( ReqlAst reql, Expression expression, Type resultType )
|
||||
{
|
||||
var subQueryExpression = expression as SubQueryExpression;
|
||||
if( subQueryExpression == null )
|
||||
return false;
|
||||
|
||||
var type = subQueryExpression.QueryModel.MainFromClause.FromExpression.Type;
|
||||
|
||||
if( type.GetTypeInfo().IsGenericType
|
||||
&& type.GetGenericTypeDefinition() == typeof( IGrouping<,> ) )
|
||||
{
|
||||
if( subQueryExpression.QueryModel.ResultOperators[0] is AnyResultOperator )
|
||||
return true;
|
||||
throw new NotImplementedException( "This filter is not supported for GroupBy" );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public ReqlExpr Parse( ReqlExpr expression, QueryModel queryModel, Expression predicate )
|
||||
{
|
||||
return expression.Filter( x => x["reduction"].Contains( reqlExpr => GetWhereReqlAst( reqlExpr, predicate ) ) );
|
||||
}
|
||||
|
||||
private static ReqlExpr GetWhereReqlAst( ReqlExpr reqlExpr, Expression predicate )
|
||||
{
|
||||
var subQueryExpression = predicate as SubQueryExpression;
|
||||
var where = subQueryExpression.QueryModel.BodyClauses[0] as WhereClause;
|
||||
|
||||
var visitor = new ExpressionVisitor( reqlExpr, subQueryExpression.QueryModel.MainFromClause.ItemType );
|
||||
visitor.Visit( where.Predicate );
|
||||
return visitor.Current;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bae9ddf53cce69543be098c155e50c24
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
using System;
|
||||
using System.Linq.Expressions;
|
||||
using Remotion.Linq;
|
||||
using RethinkDb.Driver.Ast;
|
||||
|
||||
namespace RethinkDb.Driver.Linq.WhereClauseParsers
|
||||
{
|
||||
public interface IWhereClauseParser
|
||||
{
|
||||
bool IsAppropriate( ReqlAst reql, Expression expression, Type resultType );
|
||||
ReqlExpr Parse( ReqlExpr expression, QueryModel queryModel, Expression predicate );
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5e2c572257c646e42abea70e540719e5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
using System.Linq.Expressions;
|
||||
using Remotion.Linq;
|
||||
using RethinkDb.Driver.Ast;
|
||||
using RethinkDb.Driver.Linq.Attributes;
|
||||
|
||||
namespace RethinkDb.Driver.Linq.WhereClauseParsers
|
||||
{
|
||||
public class PrimaryIndexParser : BaseIndexParser<PrimaryIndexAttribute>
|
||||
{
|
||||
public override ReqlExpr Parse( ReqlExpr expression, QueryModel queryModel, Expression predicate )
|
||||
{
|
||||
var binaryExpression = (BinaryExpression)predicate;
|
||||
var value = GetValue( binaryExpression );
|
||||
|
||||
return ( (Table)expression ).Get( value );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 14365077527b4b348b68c74cd25ea232
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
using System.Linq.Expressions;
|
||||
using Remotion.Linq;
|
||||
using RethinkDb.Driver.Ast;
|
||||
using RethinkDb.Driver.Linq.Attributes;
|
||||
using RethinkDb.Driver.Utils;
|
||||
|
||||
namespace RethinkDb.Driver.Linq.WhereClauseParsers
|
||||
{
|
||||
public class SecondaryIndexParser : BaseIndexParser<SecondaryIndexAttribute>
|
||||
{
|
||||
public override ReqlExpr Parse( ReqlExpr expression, QueryModel queryModel, Expression predicate )
|
||||
{
|
||||
var binaryExpression = (BinaryExpression)predicate;
|
||||
var value = GetValue( binaryExpression );
|
||||
|
||||
return ( (Table)expression ).GetAll( value ).OptArg( "index", GetIndexName( binaryExpression ) );
|
||||
}
|
||||
|
||||
private static string GetIndexName( BinaryExpression binaryExpression )
|
||||
{
|
||||
var left = binaryExpression.Left as MemberExpression;
|
||||
var memberExpression = left ?? ( (MemberExpression)binaryExpression.Right );
|
||||
return QueryHelper.GetJsonMemberName( memberExpression.Member );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2b3abba98413de94ba476d5d649d5605
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 85dec746696fa1d46aa7a4d74a50272a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
using System.Linq.Expressions;
|
||||
using Remotion.Linq;
|
||||
using Remotion.Linq.Clauses.ResultOperators;
|
||||
using RethinkDb.Driver.Ast;
|
||||
|
||||
namespace RethinkDb.Driver.Linq.WhereClauseParsers.SubQueryVisitor
|
||||
{
|
||||
public class AllSubQueryVisitor : BaseSubQueryVisitor<AllResultOperator>
|
||||
{
|
||||
public override ReqlExpr Visit( ReqlExpr reqlExpr, QueryModel queryModel )
|
||||
{
|
||||
var fromExpression = queryModel.MainFromClause.FromExpression as MemberExpression;
|
||||
var memberNameResolver = new MemberNameResolver( fromExpression );
|
||||
reqlExpr = memberNameResolver.Resolve( reqlExpr );
|
||||
reqlExpr = reqlExpr.Filter( expr => GetWhereReqlAst( expr, ( (AllResultOperator)queryModel.ResultOperators[0] ).Predicate, queryModel ).Not() );
|
||||
return reqlExpr.Count().Eq( 0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1d0bf98818a618e44895a5207ab54668
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
using Remotion.Linq;
|
||||
using Remotion.Linq.Clauses.ResultOperators;
|
||||
using RethinkDb.Driver.Ast;
|
||||
|
||||
namespace RethinkDb.Driver.Linq.WhereClauseParsers.SubQueryVisitor
|
||||
{
|
||||
public class AnySubQueryVisitor : BaseFilterableSubQueryVisitor<AnyResultOperator>
|
||||
{
|
||||
protected override ReqlExpr BuildReql( ReqlExpr reqlExpr, QueryModel queryModel ) => reqlExpr.Count().Gt( 0 );
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4128f9aaf789fd84d9283d76c74428a5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using Remotion.Linq;
|
||||
using Remotion.Linq.Clauses;
|
||||
using RethinkDb.Driver.Ast;
|
||||
|
||||
namespace RethinkDb.Driver.Linq.WhereClauseParsers.SubQueryVisitor
|
||||
{
|
||||
public abstract class BaseFilterableSubQueryVisitor<T> : BaseSubQueryVisitor<T>
|
||||
{
|
||||
public override ReqlExpr Visit( ReqlExpr reqlExpr, QueryModel queryModel )
|
||||
{
|
||||
var fromExpression = queryModel.MainFromClause.FromExpression as MemberExpression;
|
||||
var memberNameResolver = new MemberNameResolver( fromExpression );
|
||||
reqlExpr = memberNameResolver.Resolve( reqlExpr );
|
||||
if( queryModel.BodyClauses.Any() )
|
||||
reqlExpr = reqlExpr.Filter( expr => GetWhereReqlAst( expr, ( (WhereClause)queryModel.BodyClauses[0] ).Predicate, queryModel ) );
|
||||
return BuildReql( reqlExpr, queryModel );
|
||||
}
|
||||
|
||||
protected abstract ReqlExpr BuildReql( ReqlExpr reqlExpr, QueryModel queryModel );
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 44789e40a3709604581ae5adcaf85635
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using Remotion.Linq;
|
||||
using RethinkDb.Driver.Ast;
|
||||
|
||||
namespace RethinkDb.Driver.Linq.WhereClauseParsers.SubQueryVisitor
|
||||
{
|
||||
public abstract class BaseSubQueryVisitor<T> : ISubQueryVisitor
|
||||
{
|
||||
protected static ReqlExpr GetWhereReqlAst( ReqlExpr reqlExpr, Expression predicate, QueryModel queryModel )
|
||||
{
|
||||
var visitor = new ExpressionVisitor( reqlExpr, GetResultType( queryModel ) );
|
||||
visitor.Visit( predicate );
|
||||
return visitor.Current;
|
||||
}
|
||||
|
||||
protected static Type GetResultType( QueryModel queryModel )
|
||||
{
|
||||
if( !queryModel.ResultTypeOverride.GetTypeInfo().IsGenericType )
|
||||
return queryModel.ResultTypeOverride;
|
||||
return queryModel.ResultTypeOverride.GetTypeInfo().GenericTypeArguments[0];
|
||||
}
|
||||
|
||||
public virtual bool CanVisit( QueryModel queryModel )
|
||||
{
|
||||
return queryModel.ResultOperators.Any( x => x is T );
|
||||
}
|
||||
|
||||
public abstract ReqlExpr Visit( ReqlExpr reqlExpr, QueryModel queryModel );
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3a6871f9c44490c4ca39b77bfa55b9e8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using Remotion.Linq;
|
||||
using Remotion.Linq.Clauses.ResultOperators;
|
||||
using RethinkDb.Driver.Ast;
|
||||
|
||||
namespace RethinkDb.Driver.Linq.WhereClauseParsers.SubQueryVisitor
|
||||
{
|
||||
public class ContainsSubQueryVisitor : BaseSubQueryVisitor<ContainsResultOperator>
|
||||
{
|
||||
public override ReqlExpr Visit( ReqlExpr reqlExpr, QueryModel queryModel )
|
||||
{
|
||||
var fromExpression = queryModel.MainFromClause.FromExpression as ConstantExpression;
|
||||
var array = RethinkDB.R.Expr( fromExpression.Value as IEnumerable<object> );
|
||||
|
||||
var resultOperator = queryModel.ResultOperators[0] as ContainsResultOperator;
|
||||
|
||||
var memberNameResolver = new MemberNameResolver( (MemberExpression)resultOperator.Item );
|
||||
return array.Contains( memberNameResolver.Resolve( reqlExpr ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 67ccfb3b1d003a047840914b856e8ca0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
using Remotion.Linq;
|
||||
using Remotion.Linq.Clauses.ResultOperators;
|
||||
using RethinkDb.Driver.Ast;
|
||||
|
||||
namespace RethinkDb.Driver.Linq.WhereClauseParsers.SubQueryVisitor
|
||||
{
|
||||
public class CountSubQueryVisitor : BaseFilterableSubQueryVisitor<CountResultOperator>
|
||||
{
|
||||
protected override ReqlExpr BuildReql( ReqlExpr reqlExpr, QueryModel queryModel ) => reqlExpr.Count();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ef10c4e44e8129e46af3a951b3b93c70
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
using System.Linq;
|
||||
using Remotion.Linq;
|
||||
using Remotion.Linq.Clauses.ResultOperators;
|
||||
using RethinkDb.Driver.Ast;
|
||||
|
||||
namespace RethinkDb.Driver.Linq.WhereClauseParsers.SubQueryVisitor
|
||||
{
|
||||
public class FirstAndLastSubQueryVisitor : BaseFilterableSubQueryVisitor<ChoiceResultOperatorBase>
|
||||
{
|
||||
public override bool CanVisit( QueryModel queryModel )
|
||||
{
|
||||
return queryModel.ResultOperators.Any( x => x is FirstResultOperator || x is LastResultOperator );
|
||||
}
|
||||
|
||||
protected override ReqlExpr BuildReql( ReqlExpr reqlExpr, QueryModel queryModel )
|
||||
{
|
||||
reqlExpr = reqlExpr.Nth( queryModel.ResultOperators[0] is FirstResultOperator ? 0 : -1 );
|
||||
var resultOperator = (ChoiceResultOperatorBase)queryModel.ResultOperators[0];
|
||||
if( resultOperator.ReturnDefaultWhenEmpty )
|
||||
reqlExpr = reqlExpr.Default_( (object)null );
|
||||
return reqlExpr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c678f74d3d4cb2547a76ae96990b94db
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
using Remotion.Linq;
|
||||
using RethinkDb.Driver.Ast;
|
||||
|
||||
namespace RethinkDb.Driver.Linq.WhereClauseParsers.SubQueryVisitor
|
||||
{
|
||||
public interface ISubQueryVisitor
|
||||
{
|
||||
bool CanVisit( QueryModel queryModel );
|
||||
ReqlExpr Visit( ReqlExpr reqlExpr, QueryModel queryModel );
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e05c835bd205def4a8157c933b5f5133
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 441bcdda98c551544a4710798510ab01
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b3817a16ad2ea504a9e2b2a2581b0412
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace RethinkDb.Driver.Ast
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension helpers for working with the AST.
|
||||
/// </summary>
|
||||
public static class ExtensionHelper
|
||||
{
|
||||
internal static JObject ToJObject(this object anonType)
|
||||
{
|
||||
return anonType == null ? null : JObject.FromObject(anonType);
|
||||
}
|
||||
|
||||
internal static IDictionary<string, object> ToDict(this object anonType)
|
||||
{
|
||||
return anonType == null ? null : PropertyHelper.ObjectToDictionary(anonType);
|
||||
}
|
||||
/// <summary>
|
||||
/// Uses a collection as parameters for a method call.
|
||||
/// </summary>
|
||||
/// <param name="args">Same as calling params object[] overload. Instead of specifying each param, ICollection can be used for convenience.</param>
|
||||
public static object[] AsParams<T>(this ICollection<T> args)
|
||||
{
|
||||
return args.OfType<object>().ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4a823fc8988297f4aabe8019ae3310cd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
using Newtonsoft.Json.Linq;
|
||||
using RethinkDb.Driver.Net;
|
||||
using RethinkDb.Driver.Proto;
|
||||
|
||||
namespace RethinkDb.Driver.Ast
|
||||
{
|
||||
internal class Poco : ReqlExpr
|
||||
{
|
||||
private readonly object obj;
|
||||
|
||||
public Poco(object obj) : base(new TermType(), null, null)
|
||||
{
|
||||
this.obj = obj;
|
||||
}
|
||||
|
||||
|
||||
internal class PocoWriter : JTokenWriter
|
||||
{
|
||||
public override void WriteStartArray()
|
||||
{
|
||||
base.WriteStartArray();
|
||||
this.WriteValue(Proto.TermType.MAKE_ARRAY);
|
||||
base.WriteStartArray();
|
||||
}
|
||||
|
||||
public override void WriteEndArray()
|
||||
{
|
||||
base.WriteEndArray();
|
||||
base.WriteEndArray();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected internal override object Build()
|
||||
{
|
||||
JToken token;
|
||||
using( var writer = new PocoWriter() )
|
||||
{
|
||||
Converter.Serializer.Serialize(writer, this.obj);
|
||||
token = writer.Token;
|
||||
}
|
||||
return token;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 977e5c4e6b4f6364d9f1675f07332c78
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,515 +0,0 @@
|
|||
#pragma warning disable 419
|
||||
|
||||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace RethinkDb.Driver.Ast
|
||||
{
|
||||
internal class PropertyHelper
|
||||
{
|
||||
// Delegate type for a by-ref property getter
|
||||
private delegate TValue ByRefFunc<TDeclaringType, TValue>(ref TDeclaringType arg);
|
||||
|
||||
private static readonly MethodInfo CallPropertyGetterOpenGenericMethod =
|
||||
typeof(PropertyHelper).GetTypeInfo().GetDeclaredMethod(nameof(CallPropertyGetter));
|
||||
|
||||
private static readonly MethodInfo CallPropertyGetterByReferenceOpenGenericMethod =
|
||||
typeof(PropertyHelper).GetTypeInfo().GetDeclaredMethod(nameof(CallPropertyGetterByReference));
|
||||
|
||||
private static readonly MethodInfo CallNullSafePropertyGetterOpenGenericMethod =
|
||||
typeof(PropertyHelper).GetTypeInfo().GetDeclaredMethod(nameof(CallNullSafePropertyGetter));
|
||||
|
||||
private static readonly MethodInfo CallNullSafePropertyGetterByReferenceOpenGenericMethod =
|
||||
typeof(PropertyHelper).GetTypeInfo().GetDeclaredMethod(nameof(CallNullSafePropertyGetterByReference));
|
||||
|
||||
private static readonly MethodInfo CallPropertySetterOpenGenericMethod =
|
||||
typeof(PropertyHelper).GetTypeInfo().GetDeclaredMethod(nameof(CallPropertySetter));
|
||||
|
||||
// Using an array rather than IEnumerable, as target will be called on the hot path numerous times.
|
||||
private static readonly ConcurrentDictionary<Type, PropertyHelper[]> PropertiesCache =
|
||||
new ConcurrentDictionary<Type, PropertyHelper[]>();
|
||||
|
||||
private static readonly ConcurrentDictionary<Type, PropertyHelper[]> VisiblePropertiesCache =
|
||||
new ConcurrentDictionary<Type, PropertyHelper[]>();
|
||||
|
||||
private Action<object, object> _valueSetter;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a fast <see cref="PropertyHelper"/>.
|
||||
/// This constructor does not cache the helper. For caching, use <see cref="GetProperties(object)"/>.
|
||||
/// </summary>
|
||||
public PropertyHelper(PropertyInfo property)
|
||||
{
|
||||
if( property == null )
|
||||
{
|
||||
throw new ArgumentNullException(nameof(property));
|
||||
}
|
||||
|
||||
Property = property;
|
||||
Name = property.Name;
|
||||
ValueGetter = MakeFastPropertyGetter(property);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the backing <see cref="PropertyInfo"/>.
|
||||
/// </summary>
|
||||
public PropertyInfo Property { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets (or sets in derived types) the property name.
|
||||
/// </summary>
|
||||
public virtual string Name { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the property value getter.
|
||||
/// </summary>
|
||||
public Func<object, object> ValueGetter { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the property value setter.
|
||||
/// </summary>
|
||||
public Action<object, object> ValueSetter
|
||||
{
|
||||
get
|
||||
{
|
||||
if( _valueSetter == null )
|
||||
{
|
||||
// We'll allow safe races here.
|
||||
_valueSetter = MakeFastPropertySetter(Property);
|
||||
}
|
||||
|
||||
return _valueSetter;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the property value for the specified <paramref name="instance"/>.
|
||||
/// </summary>
|
||||
/// <param name="instance">The object whose property value will be returned.</param>
|
||||
/// <returns>The property value.</returns>
|
||||
public object GetValue(object instance)
|
||||
{
|
||||
return ValueGetter(instance);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the property value for the specified <paramref name="instance" />.
|
||||
/// </summary>
|
||||
/// <param name="instance">The object whose property value will be set.</param>
|
||||
/// <param name="value">The property value.</param>
|
||||
public void SetValue(object instance, object value)
|
||||
{
|
||||
ValueSetter(instance, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates and caches fast property helpers that expose getters for every public get property on the
|
||||
/// underlying type.
|
||||
/// </summary>
|
||||
/// <param name="instance">the instance to extract property accessors for.</param>
|
||||
/// <returns>a cached array of all public property getters from the underlying type of target instance.
|
||||
/// </returns>
|
||||
public static PropertyHelper[] GetProperties(object instance)
|
||||
{
|
||||
return GetProperties(instance.GetType());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates and caches fast property helpers that expose getters for every public get property on the
|
||||
/// specified type.
|
||||
/// </summary>
|
||||
/// <param name="type">the type to extract property accessors for.</param>
|
||||
/// <returns>a cached array of all public property getters from the type of target instance.
|
||||
/// </returns>
|
||||
public static PropertyHelper[] GetProperties(Type type)
|
||||
{
|
||||
return GetProperties(type, CreateInstance, PropertiesCache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>
|
||||
/// Creates and caches fast property helpers that expose getters for every non-hidden get property
|
||||
/// on the specified type.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <see cref="GetVisibleProperties"/> excludes properties defined on base types that have been
|
||||
/// hidden by definitions using the <c>new</c> keyword.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="instance">The instance to extract property accessors for.</param>
|
||||
/// <returns>
|
||||
/// A cached array of all public property getters from the instance's type.
|
||||
/// </returns>
|
||||
public static PropertyHelper[] GetVisibleProperties(object instance)
|
||||
{
|
||||
return GetVisibleProperties(instance.GetType(), CreateInstance, PropertiesCache, VisiblePropertiesCache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>
|
||||
/// Creates a caches fast property helpers that expose getters for every non-hidden get property
|
||||
/// on the specified type.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <see cref="GetVisibleProperties"/> excludes properties defined on base types that have been
|
||||
/// hidden by definitions using the <c>new</c> keyword.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="type">The type to extract property accessors for.</param>
|
||||
/// <returns>
|
||||
/// A cached array of all public property getters from the type.
|
||||
/// </returns>
|
||||
public static PropertyHelper[] GetVisibleProperties(Type type)
|
||||
{
|
||||
return GetVisibleProperties(type, CreateInstance, PropertiesCache, VisiblePropertiesCache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a single fast property getter. The result is not cached.
|
||||
/// </summary>
|
||||
/// <param name="propertyInfo">propertyInfo to extract the getter for.</param>
|
||||
/// <returns>a fast getter.</returns>
|
||||
/// <remarks>
|
||||
/// This method is more memory efficient than a dynamically compiled lambda, and about the
|
||||
/// same speed.
|
||||
/// </remarks>
|
||||
public static Func<object, object> MakeFastPropertyGetter(PropertyInfo propertyInfo)
|
||||
{
|
||||
Debug.Assert(propertyInfo != null);
|
||||
|
||||
return MakeFastPropertyGetter(
|
||||
propertyInfo,
|
||||
CallPropertyGetterOpenGenericMethod,
|
||||
CallPropertyGetterByReferenceOpenGenericMethod);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a single fast property getter which is safe for a null input object. The result is not cached.
|
||||
/// </summary>
|
||||
/// <param name="propertyInfo">propertyInfo to extract the getter for.</param>
|
||||
/// <returns>a fast getter.</returns>
|
||||
/// <remarks>
|
||||
/// This method is more memory efficient than a dynamically compiled lambda, and about the
|
||||
/// same speed.
|
||||
/// </remarks>
|
||||
public static Func<object, object> MakeNullSafeFastPropertyGetter(PropertyInfo propertyInfo)
|
||||
{
|
||||
Debug.Assert(propertyInfo != null);
|
||||
|
||||
return MakeFastPropertyGetter(
|
||||
propertyInfo,
|
||||
CallNullSafePropertyGetterOpenGenericMethod,
|
||||
CallNullSafePropertyGetterByReferenceOpenGenericMethod);
|
||||
}
|
||||
|
||||
private static Func<object, object> MakeFastPropertyGetter(
|
||||
PropertyInfo propertyInfo,
|
||||
MethodInfo propertyGetterWrapperMethod,
|
||||
MethodInfo propertyGetterByRefWrapperMethod)
|
||||
{
|
||||
Debug.Assert(propertyInfo != null);
|
||||
|
||||
// Must be a generic method with a Func<,> parameter
|
||||
Debug.Assert(propertyGetterWrapperMethod != null);
|
||||
Debug.Assert(propertyGetterWrapperMethod.IsGenericMethodDefinition);
|
||||
Debug.Assert(propertyGetterWrapperMethod.GetParameters().Length == 2);
|
||||
|
||||
// Must be a generic method with a ByRefFunc<,> parameter
|
||||
Debug.Assert(propertyGetterByRefWrapperMethod != null);
|
||||
Debug.Assert(propertyGetterByRefWrapperMethod.IsGenericMethodDefinition);
|
||||
Debug.Assert(propertyGetterByRefWrapperMethod.GetParameters().Length == 2);
|
||||
|
||||
var getMethod = propertyInfo.GetMethod;
|
||||
Debug.Assert(getMethod != null);
|
||||
Debug.Assert(!getMethod.IsStatic);
|
||||
Debug.Assert(getMethod.GetParameters().Length == 0);
|
||||
|
||||
// Instance methods in the CLR can be turned into static methods where the first parameter
|
||||
// is open over "target". This parameter is always passed by reference, so we have a code
|
||||
// path for value types and a code path for reference types.
|
||||
if( getMethod.DeclaringType.GetTypeInfo().IsValueType )
|
||||
{
|
||||
// Create a delegate (ref TDeclaringType) -> TValue
|
||||
return MakeFastPropertyGetter(
|
||||
typeof(ByRefFunc<,>),
|
||||
getMethod,
|
||||
propertyGetterByRefWrapperMethod);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create a delegate TDeclaringType -> TValue
|
||||
return MakeFastPropertyGetter(
|
||||
typeof(Func<,>),
|
||||
getMethod,
|
||||
propertyGetterWrapperMethod);
|
||||
}
|
||||
}
|
||||
|
||||
private static Func<object, object> MakeFastPropertyGetter(
|
||||
Type openGenericDelegateType,
|
||||
MethodInfo propertyGetMethod,
|
||||
MethodInfo openGenericWrapperMethod)
|
||||
{
|
||||
var typeInput = propertyGetMethod.DeclaringType;
|
||||
var typeOutput = propertyGetMethod.ReturnType;
|
||||
|
||||
var delegateType = openGenericDelegateType.MakeGenericType(typeInput, typeOutput);
|
||||
var propertyGetterDelegate = propertyGetMethod.CreateDelegate(delegateType);
|
||||
|
||||
var wrapperDelegateMethod = openGenericWrapperMethod.MakeGenericMethod(typeInput, typeOutput);
|
||||
var accessorDelegate = wrapperDelegateMethod.CreateDelegate(
|
||||
typeof(Func<object, object>),
|
||||
propertyGetterDelegate);
|
||||
|
||||
return (Func<object, object>)accessorDelegate;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a single fast property setter for reference types. The result is not cached.
|
||||
/// </summary>
|
||||
/// <param name="propertyInfo">propertyInfo to extract the setter for.</param>
|
||||
/// <returns>a fast getter.</returns>
|
||||
/// <remarks>
|
||||
/// This method is more memory efficient than a dynamically compiled lambda, and about the
|
||||
/// same speed. This only works for reference types.
|
||||
/// </remarks>
|
||||
public static Action<object, object> MakeFastPropertySetter(PropertyInfo propertyInfo)
|
||||
{
|
||||
Debug.Assert(propertyInfo != null);
|
||||
Debug.Assert(!propertyInfo.DeclaringType.GetTypeInfo().IsValueType);
|
||||
|
||||
var setMethod = propertyInfo.SetMethod;
|
||||
Debug.Assert(setMethod != null);
|
||||
Debug.Assert(!setMethod.IsStatic);
|
||||
Debug.Assert(setMethod.ReturnType == typeof(void));
|
||||
var parameters = setMethod.GetParameters();
|
||||
Debug.Assert(parameters.Length == 1);
|
||||
|
||||
// Instance methods in the CLR can be turned into static methods where the first parameter
|
||||
// is open over "target". This parameter is always passed by reference, so we have a code
|
||||
// path for value types and a code path for reference types.
|
||||
var typeInput = setMethod.DeclaringType;
|
||||
var parameterType = parameters[0].ParameterType;
|
||||
|
||||
// Create a delegate TDeclaringType -> { TDeclaringType.Property = TValue; }
|
||||
var propertySetterAsAction =
|
||||
setMethod.CreateDelegate(typeof(Action<,>).MakeGenericType(typeInput, parameterType));
|
||||
var callPropertySetterClosedGenericMethod =
|
||||
CallPropertySetterOpenGenericMethod.MakeGenericMethod(typeInput, parameterType);
|
||||
var callPropertySetterDelegate =
|
||||
callPropertySetterClosedGenericMethod.CreateDelegate(
|
||||
typeof(Action<object, object>), propertySetterAsAction);
|
||||
|
||||
return (Action<object, object>)callPropertySetterDelegate;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Given an object, adds each instance property with a public get method as a key and its
|
||||
/// associated value to a dictionary.
|
||||
///
|
||||
/// If the object is already an IDictionary{string,object} instance, then a copy
|
||||
/// is returned.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The implementation of PropertyHelper will cache the property accessors per-type. This is
|
||||
/// faster when the same type is used multiple times with ObjectToDictionary.
|
||||
/// </remarks>
|
||||
public static IDictionary<string, object> ObjectToDictionary(object value)
|
||||
{
|
||||
var dictionary = value as IDictionary<string, object>;
|
||||
if( dictionary != null )
|
||||
{
|
||||
return new Dictionary<string, object>(dictionary, StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
dictionary = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
if( value != null )
|
||||
{
|
||||
foreach( var helper in GetProperties(value) )
|
||||
{
|
||||
dictionary[helper.Name] = helper.GetValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
private static PropertyHelper CreateInstance(PropertyInfo property)
|
||||
{
|
||||
return new PropertyHelper(property);
|
||||
}
|
||||
|
||||
// Called via reflection
|
||||
private static object CallPropertyGetter<TDeclaringType, TValue>(
|
||||
Func<TDeclaringType, TValue> getter,
|
||||
object target)
|
||||
{
|
||||
return getter((TDeclaringType)target);
|
||||
}
|
||||
|
||||
// Called via reflection
|
||||
private static object CallPropertyGetterByReference<TDeclaringType, TValue>(
|
||||
ByRefFunc<TDeclaringType, TValue> getter,
|
||||
object target)
|
||||
{
|
||||
var unboxed = (TDeclaringType)target;
|
||||
return getter(ref unboxed);
|
||||
}
|
||||
|
||||
// Called via reflection
|
||||
private static object CallNullSafePropertyGetter<TDeclaringType, TValue>(
|
||||
Func<TDeclaringType, TValue> getter,
|
||||
object target)
|
||||
{
|
||||
if( target == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return getter((TDeclaringType)target);
|
||||
}
|
||||
|
||||
// Called via reflection
|
||||
private static object CallNullSafePropertyGetterByReference<TDeclaringType, TValue>(
|
||||
ByRefFunc<TDeclaringType, TValue> getter,
|
||||
object target)
|
||||
{
|
||||
if( target == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var unboxed = (TDeclaringType)target;
|
||||
return getter(ref unboxed);
|
||||
}
|
||||
|
||||
private static void CallPropertySetter<TDeclaringType, TValue>(
|
||||
Action<TDeclaringType, TValue> setter,
|
||||
object target,
|
||||
object value)
|
||||
{
|
||||
setter((TDeclaringType)target, (TValue)value);
|
||||
}
|
||||
|
||||
protected static PropertyHelper[] GetVisibleProperties(
|
||||
Type type,
|
||||
Func<PropertyInfo, PropertyHelper> createPropertyHelper,
|
||||
ConcurrentDictionary<Type, PropertyHelper[]> allPropertiesCache,
|
||||
ConcurrentDictionary<Type, PropertyHelper[]> visiblePropertiesCache)
|
||||
{
|
||||
PropertyHelper[] result;
|
||||
if( visiblePropertiesCache.TryGetValue(type, out result) )
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
// The simple and common case, this is normal POCO object - no need to allocate.
|
||||
var allPropertiesDefinedOnType = true;
|
||||
var allProperties = GetProperties(type, createPropertyHelper, allPropertiesCache);
|
||||
foreach( var propertyHelper in allProperties )
|
||||
{
|
||||
if( propertyHelper.Property.DeclaringType != type )
|
||||
{
|
||||
allPropertiesDefinedOnType = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( allPropertiesDefinedOnType )
|
||||
{
|
||||
result = allProperties;
|
||||
visiblePropertiesCache.TryAdd(type, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
// There's some inherited properties here, so we need to check for hiding via 'new'.
|
||||
var filteredProperties = new List<PropertyHelper>(allProperties.Length);
|
||||
foreach( var propertyHelper in allProperties )
|
||||
{
|
||||
var declaringType = propertyHelper.Property.DeclaringType;
|
||||
if( declaringType == type )
|
||||
{
|
||||
filteredProperties.Add(propertyHelper);
|
||||
continue;
|
||||
}
|
||||
|
||||
// If this property was declared on a base type then look for the definition closest to the
|
||||
// the type to see if we should include it.
|
||||
var ignoreProperty = false;
|
||||
|
||||
// Walk up the hierarchy until we find the type that actually declares this
|
||||
// PropertyInfo.
|
||||
var currentTypeInfo = type.GetTypeInfo();
|
||||
var declaringTypeInfo = declaringType.GetTypeInfo();
|
||||
while( currentTypeInfo != null && currentTypeInfo != declaringTypeInfo )
|
||||
{
|
||||
// We've found a 'more proximal' public definition
|
||||
var declaredProperty = currentTypeInfo.GetDeclaredProperty(propertyHelper.Name);
|
||||
if( declaredProperty != null )
|
||||
{
|
||||
ignoreProperty = true;
|
||||
break;
|
||||
}
|
||||
|
||||
currentTypeInfo = currentTypeInfo.BaseType?.GetTypeInfo();
|
||||
}
|
||||
|
||||
if( !ignoreProperty )
|
||||
{
|
||||
filteredProperties.Add(propertyHelper);
|
||||
}
|
||||
}
|
||||
|
||||
result = filteredProperties.ToArray();
|
||||
visiblePropertiesCache.TryAdd(type, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
protected static PropertyHelper[] GetProperties(
|
||||
Type type,
|
||||
Func<PropertyInfo, PropertyHelper> createPropertyHelper,
|
||||
ConcurrentDictionary<Type, PropertyHelper[]> cache)
|
||||
{
|
||||
// Unwrap nullable types. This means Nullable<T>.Value and Nullable<T>.HasValue will not be
|
||||
// part of the sequence of properties returned by this method.
|
||||
type = Nullable.GetUnderlyingType(type) ?? type;
|
||||
|
||||
PropertyHelper[] helpers;
|
||||
if( !cache.TryGetValue(type, out helpers) )
|
||||
{
|
||||
// We avoid loading indexed properties using the Where statement.
|
||||
var properties = type.GetRuntimeProperties().Where(IsInterestingProperty);
|
||||
|
||||
var typeInfo = type.GetTypeInfo();
|
||||
if( typeInfo.IsInterface )
|
||||
{
|
||||
// Reflection does not return information about inherited properties on the interface itself.
|
||||
properties = properties.Concat(typeInfo.ImplementedInterfaces.SelectMany(
|
||||
interfaceType => interfaceType.GetRuntimeProperties().Where(IsInterestingProperty)));
|
||||
}
|
||||
|
||||
helpers = properties.Select(p => createPropertyHelper(p)).ToArray();
|
||||
cache.TryAdd(type, helpers);
|
||||
}
|
||||
|
||||
return helpers;
|
||||
}
|
||||
|
||||
// Indexed properties are not useful (or valid) for grabbing properties off an object.
|
||||
private static bool IsInterestingProperty(PropertyInfo property)
|
||||
{
|
||||
return property.GetIndexParameters().Length == 0 &&
|
||||
property.GetMethod != null &&
|
||||
property.GetMethod.IsPublic &&
|
||||
!property.GetMethod.IsStatic;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1dffb6ae397451d4984cf8a0dce3796e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
#pragma warning disable 1591
|
||||
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using RethinkDb.Driver.Model;
|
||||
using RethinkDb.Driver.Proto;
|
||||
|
||||
namespace RethinkDb.Driver.Ast
|
||||
{
|
||||
/* An instance for a query that has been sent to the server. Keeps
|
||||
* track of its token, the args to .run() it was called with, and its
|
||||
* query type.
|
||||
*/
|
||||
|
||||
/// <summary>
|
||||
/// DO NOT USE DIRECTLY
|
||||
/// </summary>
|
||||
public class Query
|
||||
{
|
||||
public QueryType Type { get; }
|
||||
public long Token { get; }
|
||||
public ReqlAst Term { get; }
|
||||
public OptArgs GlobalOptions { get; }
|
||||
|
||||
public Query(QueryType type, long token, ReqlAst term, OptArgs globalOptions)
|
||||
{
|
||||
this.Type = type;
|
||||
this.Token = token;
|
||||
this.Term = term;
|
||||
this.GlobalOptions = globalOptions;
|
||||
}
|
||||
|
||||
public Query(QueryType type, long token) : this(type, token, null, null)
|
||||
{
|
||||
}
|
||||
|
||||
public static Query Stop(long token)
|
||||
{
|
||||
return new Query(QueryType.STOP, token, null, null);
|
||||
}
|
||||
|
||||
public static Query Continue(long token)
|
||||
{
|
||||
return new Query(QueryType.CONTINUE, token, null, null);
|
||||
}
|
||||
|
||||
public static Query Start(long token, ReqlAst term, OptArgs globalOptions)
|
||||
{
|
||||
return new Query(QueryType.START, token, term, globalOptions);
|
||||
}
|
||||
|
||||
public static Query ServerInfo(long token)
|
||||
{
|
||||
return new Query(QueryType.SERVER_INFO, token, null, null);
|
||||
}
|
||||
|
||||
public static Query NoReplyWait(long token)
|
||||
{
|
||||
return new Query(QueryType.NOREPLY_WAIT, token, null, null);
|
||||
}
|
||||
|
||||
public virtual string Serialize()
|
||||
{
|
||||
var queryArr = new JArray();
|
||||
|
||||
queryArr.Add(Type);
|
||||
|
||||
if( Term != null )
|
||||
{
|
||||
queryArr.Add(Term.Build());
|
||||
}
|
||||
if( GlobalOptions != null )
|
||||
{
|
||||
queryArr.Add(ReqlAst.BuildOptarg(GlobalOptions));
|
||||
}
|
||||
|
||||
return queryArr.ToString(Formatting.None);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: cef144145ff323247ab108fe4eaa76c5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,450 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using RethinkDb.Driver.Model;
|
||||
using RethinkDb.Driver.Net;
|
||||
using RethinkDb.Driver.Proto;
|
||||
using RethinkDb.Driver.Utils;
|
||||
|
||||
namespace RethinkDb.Driver.Ast
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class for all reql queries.
|
||||
/// </summary>
|
||||
public class ReqlAst
|
||||
{
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
protected internal TermType TermType { get; }
|
||||
protected internal Arguments Args { get; }
|
||||
protected internal OptArgs OptArgs { get; }
|
||||
|
||||
protected internal ReqlAst(TermType termType, Arguments args, OptArgs optargs)
|
||||
{
|
||||
this.TermType = termType;
|
||||
this.Args = args ?? new Arguments();
|
||||
this.OptArgs = optargs ?? new OptArgs();
|
||||
}
|
||||
|
||||
protected internal virtual object Build()
|
||||
{
|
||||
// Create a JSON object from the Ast
|
||||
JArray list = new JArray();
|
||||
list.Add(TermType);
|
||||
if( Args.Count > 0 )
|
||||
{
|
||||
var collect = Args.Select(a => { return a.Build(); });
|
||||
list.Add(new JArray(collect));
|
||||
}
|
||||
else
|
||||
{
|
||||
list.Add(new JArray());
|
||||
}
|
||||
|
||||
if( OptArgs.Count > 0 )
|
||||
{
|
||||
list.Add(BuildOptarg(this.OptArgs));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
protected internal static JObject BuildOptarg(OptArgs opts)
|
||||
{
|
||||
var dict = opts.ToDictionary(kvp => kvp.Key, kvp => kvp.Value.Build());
|
||||
return JObject.FromObject(dict);
|
||||
}
|
||||
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
#region DYNAMIC LANGUAGE RUNTIME (DLR) RUNNERS
|
||||
|
||||
/// <summary>
|
||||
/// Runs the query on the connection. If you know the response type
|
||||
/// of your query, T (SUCCESS_ATOM) or Cursor[T] (SUCCESS_SEQUENCE or SUCCESS_PARTIAL)
|
||||
/// it's recommended to use `.RunAtom`, `.RunCursor` or `.RunResult` helpers
|
||||
/// as they offer a slight edge in performance since both bypass the
|
||||
/// dynamic language runtime execution engine.
|
||||
/// </summary>
|
||||
/// <returns>Returns T or Cursor[T]</returns>
|
||||
public virtual Task<dynamic> RunAsync<T>(IConnection conn, object runOpts = null, CancellationToken cancelToken = default)
|
||||
{
|
||||
return conn.RunAsync<T>(this, runOpts, cancelToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs the query on the connection. If you know the response type
|
||||
/// of your query, T (SUCCESS_ATOM) or Cursor[T] (SUCCESS_SEQUENCE or SUCCESS_PARTIAL)
|
||||
/// it's recommended to use `.RunAtom`, `.RunCursor` or `.RunResult` helpers
|
||||
/// as they offer a slight edge in performance since both bypass the
|
||||
/// dynamic language runtime execution engine.
|
||||
/// </summary>
|
||||
/// <returns>Returns T or Cursor[T]</returns>
|
||||
public virtual Task<dynamic> RunAsync<T>(IConnection conn, CancellationToken cancelToken)
|
||||
{
|
||||
return RunAsync<T>(conn, null, cancelToken);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Runs the query on the connection. If you know the response type
|
||||
/// of your query, T (SUCCESS_ATOM) or Cursor[T] (SUCCESS_SEQUENCE or SUCCESS_PARTIAL)
|
||||
/// it's recommended to use `.RunAtom`, `.RunCursor` or `.RunResult` helpers
|
||||
/// as they offer a slight edge in performance since both bypass the
|
||||
/// dynamic language runtime execution engine.
|
||||
/// </summary>
|
||||
/// <returns>Returns T or Cursor[T]</returns>
|
||||
/// /// <param name="conn">connection</param>
|
||||
/// <param name="runOpts">global anonymous type optional arguments</param>
|
||||
/// <param name="cancelToken">Cancellation token used to stop *waiting* for a query response. The cancellation token does not cancel the query's execution on the server.</param>
|
||||
public virtual Task<dynamic> RunAsync(IConnection conn, object runOpts = null, CancellationToken cancelToken = default)
|
||||
{
|
||||
return RunAsync<dynamic>(conn, runOpts, cancelToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs the query on the connection. If you know the response type
|
||||
/// of your query, T (SUCCESS_ATOM) or Cursor[T] (SUCCESS_SEQUENCE or SUCCESS_PARTIAL)
|
||||
/// it's recommended to use `.RunAtom`, `.RunCursor` or `.RunResult` helpers
|
||||
/// as they offer a slight edge in performance since both bypass the
|
||||
/// dynamic language runtime execution engine.
|
||||
/// </summary>
|
||||
/// <returns>Returns T or Cursor[T]</returns>
|
||||
/// /// <param name="conn">connection</param>
|
||||
/// <param name="cancelToken">Cancellation token used to stop *waiting* for a query response. The cancellation token does not cancel the query's execution on the server.</param>
|
||||
public virtual Task<dynamic> RunAsync(IConnection conn, CancellationToken cancelToken)
|
||||
{
|
||||
return RunAsync(conn, null, cancelToken);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Runs the query on the connection. If you know the response type
|
||||
/// of your query, T (SUCCESS_ATOM) or Cursor[T] (SUCCESS_SEQUENCE or SUCCESS_PARTIAL)
|
||||
/// it's recommended to use `.RunAtom`, `.RunCursor` or `.RunResult` helpers
|
||||
/// as they offer a slight edge in performance since both bypass the
|
||||
/// dynamic language runtime execution engine.
|
||||
/// </summary>
|
||||
/// <returns>Returns T or Cursor[T]</returns>
|
||||
public virtual dynamic Run<T>(IConnection conn, object runOpts = null)
|
||||
{
|
||||
return RunAsync<T>(conn, runOpts).WaitSync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs the query on the connection. If you know the response type
|
||||
/// of your query, T (SUCCESS_ATOM) or Cursor[T] (SUCCESS_SEQUENCE or SUCCESS_PARTIAL)
|
||||
/// it's recommended to use `.RunAtom`, `.RunCursor` or `.RunResult` helpers
|
||||
/// as they offer a slight edge in performance since both bypass the
|
||||
/// dynamic language runtime execution engine.
|
||||
/// </summary>
|
||||
/// <returns>Returns T or Cursor[T]</returns>
|
||||
public virtual dynamic Run(IConnection conn, object runOpts = null)
|
||||
{
|
||||
return Run<dynamic>(conn, runOpts);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region RESPONSE TYPED RUNNERS
|
||||
|
||||
/// <summary>
|
||||
/// Executes a query with no expected response. Useful for fire-and-forget queries like insert, update.
|
||||
/// </summary>
|
||||
public void RunNoReply(IConnection conn, object runOpts = null)
|
||||
{
|
||||
conn.RunNoReply(this, runOpts);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this method if you're expecting a cursor (SUCCESS_SEQUENCE or SUCCESS_PARTIAL) response
|
||||
/// from your query. This method offers a slight edge in performance without the need for the
|
||||
/// dynamic language runtime like the run() method uses.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="conn">connection</param>
|
||||
/// <param name="runOpts">global anonymous type optional arguments</param>
|
||||
/// <param name="cancelToken">Cancellation token used to stop *waiting* for a query response. The cancellation token does not cancel the query's execution on the server.</param>
|
||||
/// <returns>A Cursor</returns>
|
||||
public virtual Task<Cursor<T>> RunCursorAsync<T>(IConnection conn, object runOpts = null, CancellationToken cancelToken = default)
|
||||
{
|
||||
return conn.RunCursorAsync<T>(this, runOpts, cancelToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this method if you're expecting a cursor (SUCCESS_SEQUENCE or SUCCESS_PARTIAL) response
|
||||
/// from your query. This method offers a slight edge in performance without the need for the
|
||||
/// dynamic language runtime like the run() method uses.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="conn">connection</param>
|
||||
/// <param name="cancelToken">Cancellation token used to stop *waiting* for a query response. The cancellation token does not cancel the query's execution on the server.</param>
|
||||
/// <returns>A Cursor</returns>
|
||||
public virtual Task<Cursor<T>> RunCursorAsync<T>(IConnection conn, CancellationToken cancelToken)
|
||||
{
|
||||
return RunCursorAsync<T>(conn, null, cancelToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this method if you're expecting a cursor (SUCCESS_SEQUENCE or SUCCESS_PARTIAL) response
|
||||
/// from your query. This method offers a slight edge in performance without the need for the
|
||||
/// dynamic language runtime like the run() method uses.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="conn">connection</param>
|
||||
/// <param name="runOpts">global anonymous type optional arguments</param>
|
||||
/// <returns>A Cursor</returns>
|
||||
public virtual Cursor<T> RunCursor<T>(IConnection conn, object runOpts = null)
|
||||
{
|
||||
return RunCursorAsync<T>(conn, runOpts).WaitSync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this method if you're expecting SUCCESS_ATOM response from your query. This
|
||||
/// method offers a slight edge in performance without the need for the
|
||||
/// dynamic language runtime like the run() method uses.
|
||||
/// </summary>
|
||||
/// <param name="conn">connection</param>
|
||||
/// <param name="runOpts">global anonymous type optional arguments</param>
|
||||
/// <param name="cancelToken">Cancellation token used to stop *waiting* for a query response. The cancellation token does not cancel the query's execution on the server.</param>
|
||||
public virtual Task<T> RunAtomAsync<T>(IConnection conn, object runOpts = null, CancellationToken cancelToken = default)
|
||||
{
|
||||
return conn.RunAtomAsync<T>(this, runOpts, cancelToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this method if you're expecting SUCCESS_ATOM response from your query. This
|
||||
/// method offers a slight edge in performance without the need for the
|
||||
/// dynamic language runtime like the run() method uses.
|
||||
/// </summary>
|
||||
/// <param name="conn">connection</param>
|
||||
/// <param name="cancelToken">Cancellation token used to stop *waiting* for a query response. The cancellation token does not cancel the query's execution on the server.</param>
|
||||
public virtual Task<T> RunAtomAsync<T>(IConnection conn, CancellationToken cancelToken)
|
||||
{
|
||||
return RunAtomAsync<T>(conn, null, cancelToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this method if you're expecting SUCCESS_ATOM response from your query. This
|
||||
/// method offers a slight edge in performance without the need for the
|
||||
/// dynamic language runtime like the run() method uses.
|
||||
/// </summary>
|
||||
/// <param name="conn">connection</param>
|
||||
/// <param name="runOpts">global anonymous type optional arguments</param>
|
||||
public virtual T RunAtom<T>(IConnection conn, object runOpts = null)
|
||||
{
|
||||
return RunAtomAsync<T>(conn, runOpts).WaitSync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this method if you're expecting SUCCESS_ATOM or SUCCESS_SEQUENCE response from your query. This
|
||||
/// method offers a slight edge in performance without the need for the
|
||||
/// dynamic language runtime like the run() method uses. Consider using RunAtom or RunCursor if your
|
||||
/// response is either SUCCESS_ATOM or SUCCESS_SEQUENCE respectively. Exercise caution using this method
|
||||
/// with large datasets as the server can switch responses from SUCESS_SEQUENCE to SUCCESS_PARTIAL for the
|
||||
/// same exact query. Refer to the online documentation for this run helper.
|
||||
/// </summary>
|
||||
/// <param name="conn">connection</param>
|
||||
/// <param name="runOpts">global anonymous type optional arguments</param>
|
||||
/// <param name="cancelToken">Cancellation token used to stop *waiting* for a query response. The cancellation token does not cancel the query's execution on the server.</param>
|
||||
public virtual Task<T> RunResultAsync<T>(IConnection conn, object runOpts = null, CancellationToken cancelToken = default)
|
||||
{
|
||||
return conn.RunResultAsync<T>(this, runOpts, cancelToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this method if you're expecting SUCCESS_ATOM or SUCCESS_SEQUENCE response from your query. This
|
||||
/// method offers a slight edge in performance without the need for the
|
||||
/// dynamic language runtime like the run() method uses. Consider using RunAtom or RunCursor if your
|
||||
/// response is either SUCCESS_ATOM or SUCCESS_SEQUENCE respectively. Exercise caution using this method
|
||||
/// with large datasets as the server can switch responses from SUCESS_SEQUENCE to SUCCESS_PARTIAL for the
|
||||
/// same exact query. Refer to the online documentation for this run helper.
|
||||
/// </summary>
|
||||
/// <param name="conn">connection</param>
|
||||
/// <param name="cancelToken">Cancellation token used to stop *waiting* for a query response. The cancellation token does not cancel the query's execution on the server.</param>
|
||||
public virtual Task<T> RunResultAsync<T>(IConnection conn, CancellationToken cancelToken)
|
||||
{
|
||||
return RunResultAsync<T>(conn, null, cancelToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this method if you're expecting SUCCESS_ATOM or SUCCESS_SEQUENCE response from your query. This
|
||||
/// method offers a slight edge in performance without the need for the
|
||||
/// dynamic language runtime like the run() method uses. Consider using RunAtom or RunCursor if your
|
||||
/// response is either SUCCESS_ATOM or SUCCESS_SEQUENCE respectively. Exercise caution using this method
|
||||
/// with large datasets as the server can switch responses from SUCESS_SEQUENCE to SUCCESS_PARTIAL for the
|
||||
/// same exact query. Refer to the online documentation for this run helper.
|
||||
/// </summary>
|
||||
/// <param name="conn">connection</param>
|
||||
/// <param name="runOpts">global anonymous type optional arguments</param>
|
||||
public virtual T RunResult<T>(IConnection conn, object runOpts = null)
|
||||
{
|
||||
return RunResultAsync<T>(conn, runOpts).WaitSync();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region EXTRA RUN HELPERS
|
||||
|
||||
/// <summary>
|
||||
/// OBSOLETE: Please use the .RunWriteAsync() method instead.
|
||||
/// </summary>
|
||||
[Obsolete("The .RunResultAsync() method has been renamed to .RunWriteAsync(). Please use the new method name instead.", error: false)]
|
||||
public virtual Task<Result> RunResultAsync(IConnection conn, object runOpts = null, CancellationToken cancelToken = default)
|
||||
{
|
||||
return RunWriteAsync(conn, runOpts, cancelToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OBSOLETE: Please use .RunWriteAsync() method instead.
|
||||
/// </summary>
|
||||
[Obsolete("The .RunResultAsync() method has been renamed to .RunWriteAsync(). Please use the new method name instead.", error: false)]
|
||||
public virtual Task<Result> RunResultAsync(IConnection conn, CancellationToken cancelToken)
|
||||
{
|
||||
return RunWriteAsync(conn, null, cancelToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OBSOLETE: Please use .RunWrite() method instead.
|
||||
/// </summary>
|
||||
[Obsolete("The .RunResult() method has been renamed to .RunWrite(). Please use the new method name instead.", error: false)]
|
||||
public virtual Result RunResult(IConnection conn, object runOpts = null)
|
||||
{
|
||||
return RunWriteAsync(conn, runOpts).WaitSync();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Helper shortcut for DML type of queries that returns # of inserts, deletes, errors.
|
||||
/// This method bypasses the dynamic language runtime for extra performance.
|
||||
/// </summary>
|
||||
/// <param name="conn">connection</param>
|
||||
/// <param name="runOpts">global anonymous type optional arguments</param>
|
||||
/// <param name="cancelToken">Cancellation token used to stop *waiting* for a query response. The cancellation token does not cancel the query's execution on the server.</param>
|
||||
public virtual Task<Result> RunWriteAsync(IConnection conn, object runOpts = null, CancellationToken cancelToken = default)
|
||||
{
|
||||
return conn.RunAtomAsync<Result>(this, runOpts, cancelToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper shortcut for DML type of queries that returns # of inserts, deletes, errors.
|
||||
/// This method bypasses the dynamic language runtime for extra performance.
|
||||
/// </summary>
|
||||
/// <param name="conn">connection</param>
|
||||
/// <param name="cancelToken">Cancellation token used to stop *waiting* for a query response. The cancellation token does not cancel the query's execution on the server.</param>
|
||||
public virtual Task<Result> RunWriteAsync(IConnection conn, CancellationToken cancelToken)
|
||||
{
|
||||
return RunWriteAsync(conn, null, cancelToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper shortcut for DML type of queries that returns # of inserts, deletes, errors.
|
||||
/// This method bypasses the dynamic language runtime for extra performance.
|
||||
/// </summary>
|
||||
/// <param name="conn">connection</param>
|
||||
/// <param name="runOpts">global anonymous type optional arguments</param>
|
||||
public virtual Result RunWrite(IConnection conn, object runOpts = null)
|
||||
{
|
||||
return RunWriteAsync(conn, runOpts).WaitSync();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Runs a query on the server and returns the raw <see cref="Response"/> object in an unsafe way
|
||||
/// with minimal client-side processing. The unbridled use of this method can
|
||||
/// lead to memory leaks on both the client and server. This method should only
|
||||
/// be used in well-understood and advanced scenarios.
|
||||
/// </summary>
|
||||
/// <param name="conn">The connection object</param>
|
||||
/// <param name="runOpts">global anonymous type optional arguments</param>
|
||||
/// <param name="cancelToken">Cancellation token used to stop *waiting* for a query response. The cancellation token does not cancel the query's execution on the server.</param>
|
||||
public virtual Task<Response> RunUnsafeAsync(IConnection conn, object runOpts = null, CancellationToken cancelToken = default)
|
||||
{
|
||||
return conn.RunUnsafeAsync(this, runOpts, cancelToken);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Helper shortcut for change feeds, use if your query is expecting an infinite changes() stream.
|
||||
/// This method bypasses the dynamic language runtime for extra performance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The document type of new/old value</typeparam>
|
||||
/// <param name="conn">connection</param>
|
||||
/// <param name="runOpts">global anonymous type optional arguments</param>
|
||||
/// <param name="cancelToken">Cancellation token used to stop *waiting* for a query response. The cancellation token does not cancel the query's execution on the server.</param>
|
||||
public virtual Task<Cursor<Change<T>>> RunChangesAsync<T>(IConnection conn, object runOpts = null, CancellationToken cancelToken = default)
|
||||
{
|
||||
return conn.RunCursorAsync<Change<T>>(this, runOpts, cancelToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper shortcut for change feeds, use if your query is expecting an infinite changes() stream.
|
||||
/// This method bypasses the dynamic language runtime for extra performance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The document type of new/old value</typeparam>
|
||||
/// <param name="conn">connection</param>
|
||||
/// <param name="cancelToken">Cancellation token used to stop *waiting* for a query response. The cancellation token does not cancel the query's execution on the server.</param>
|
||||
public virtual Task<Cursor<Change<T>>> RunChangesAsync<T>(IConnection conn, CancellationToken cancelToken)
|
||||
{
|
||||
return RunChangesAsync<T>(conn, null, cancelToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper shortcut for change feeds, use if your query is expecting an infinite changes() stream.
|
||||
/// This method bypasses the dynamic language runtime for extra performance.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The document type of new/old value</typeparam>
|
||||
/// <param name="conn">connection</param>
|
||||
/// <param name="runOpts">global anonymous type optional arguments</param>
|
||||
public virtual Cursor<Change<T>> RunChanges<T>(IConnection conn, object runOpts = null)
|
||||
{
|
||||
return RunChangesAsync<T>(conn, runOpts).WaitSync();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Helper shortcut for grouping queries.
|
||||
/// This method bypasses the dynamic language runtime for extra performance.
|
||||
/// </summary>
|
||||
/// <typeparam name="TKey">The key type of how items are grouped</typeparam>
|
||||
/// <typeparam name="TItem">The type of items</typeparam>
|
||||
/// <param name="conn">connection</param>
|
||||
/// <param name="runOpts">global anonymous type optional arguments</param>
|
||||
/// <param name="cancelToken">Cancellation token used to stop *waiting* for a query response. The cancellation token does not cancel the query's execution on the server.</param>
|
||||
public virtual async Task<IEnumerable<GroupedResult<TKey, TItem>>> RunGroupingAsync<TKey, TItem>(IConnection conn, object runOpts = null,
|
||||
CancellationToken cancelToken = default)
|
||||
{
|
||||
var tsk = await RunAtomAsync<GroupedResultSet<TKey, TItem>>(conn, runOpts, cancelToken).ConfigureAwait(false);
|
||||
return tsk;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper shortcut for grouping queries.
|
||||
/// This method bypasses the dynamic language runtime for extra performance.
|
||||
/// </summary>
|
||||
/// <typeparam name="TKey">The key type of how items are grouped</typeparam>
|
||||
/// <typeparam name="TItem">The type of items</typeparam>
|
||||
/// <param name="conn">connection</param>
|
||||
/// <param name="cancelToken">Cancellation token used to stop *waiting* for a query response. The cancellation token does not cancel the query's execution on the server.</param>
|
||||
public virtual Task<IEnumerable<GroupedResult<TKey, TItem>>> RunGroupingAsync<TKey, TItem>(IConnection conn, CancellationToken cancelToken)
|
||||
{
|
||||
return RunGroupingAsync<TKey, TItem>(conn, null, cancelToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper shortcut for grouping queries.
|
||||
/// This method bypasses the dynamic language runtime for extra performance.
|
||||
/// </summary>
|
||||
/// <typeparam name="TKey">The key type of how items are grouped</typeparam>
|
||||
/// <typeparam name="TItem">The type of items</typeparam>
|
||||
/// <param name="conn">connection</param>
|
||||
/// <param name="runOpts">global anonymous type optional arguments</param>
|
||||
public virtual IEnumerable<GroupedResult<TKey, TItem>> RunGrouping<TKey, TItem>(IConnection conn, object runOpts = null)
|
||||
{
|
||||
return RunAtomAsync<GroupedResultSet<TKey, TItem>>(conn, runOpts).WaitSync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 525d7b2d52e0ac044a7b5761bed6ef78
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,194 +0,0 @@
|
|||
#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
|
||||
using System;
|
||||
|
||||
namespace RethinkDb.Driver.Ast
|
||||
{
|
||||
//Partial class for overloads expression overloads! :)
|
||||
//Cool man. Yeeah. That's right. So 1337.
|
||||
#pragma warning disable 660,661
|
||||
public partial class ReqlExpr
|
||||
#pragma warning restore 660,661
|
||||
{
|
||||
#region INDEXERS, READ WARNING
|
||||
// WARNING:
|
||||
// ANY ADDITIONAL INDEXERS YOU SPECIFY HERE MUST BE NEWLY
|
||||
// IMPLEMENTED IN THE AST SUBCLASS TEMPLATE TO BE PROPERLY
|
||||
// RESOLVED DURING OPERATOR RESOLUTION. REGEN OF THE AST
|
||||
// IS REQUIRED.
|
||||
//
|
||||
// SEE ReqlExprHelpers SECTION IN AstSublcassTemplate FOR
|
||||
// MORE INFORMATION.
|
||||
///
|
||||
/// <summary>
|
||||
/// Get a single field from an object. If called on a sequence, gets that field from every object in the sequence, skipping objects that lack it.
|
||||
/// </summary>
|
||||
/// <param name="bracket"></param>
|
||||
public Bracket this[string bracket] => this.bracket(bracket);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get the nth element of a sequence, counting from zero. If the argument is negative, count from the last element.
|
||||
/// </summary>
|
||||
/// <param name="bracket"></param>
|
||||
/// <returns></returns>
|
||||
public Bracket this[int bracket] => this.bracket(bracket);
|
||||
#endregion
|
||||
|
||||
public static ReqlExpr operator >(ReqlExpr a, ReqlExpr b)
|
||||
{
|
||||
return a.gt(b);
|
||||
}
|
||||
|
||||
public static ReqlExpr operator <(ReqlExpr a, ReqlExpr b)
|
||||
{
|
||||
return a.lt(b);
|
||||
}
|
||||
|
||||
public static ReqlExpr operator >=(ReqlExpr a, ReqlExpr b)
|
||||
{
|
||||
return a.ge(b);
|
||||
}
|
||||
|
||||
public static ReqlExpr operator <=(ReqlExpr a, ReqlExpr b)
|
||||
{
|
||||
return a.le(b);
|
||||
}
|
||||
|
||||
public static ReqlExpr operator ==(ReqlExpr a, ReqlExpr b)
|
||||
{
|
||||
return a.eq(b);
|
||||
}
|
||||
|
||||
public static ReqlExpr operator !=(ReqlExpr a, ReqlExpr b)
|
||||
{
|
||||
return a.ne(b);
|
||||
}
|
||||
|
||||
public static ReqlExpr operator +(ReqlExpr a, ReqlExpr b)
|
||||
{
|
||||
return a.add(b);
|
||||
}
|
||||
|
||||
public static ReqlExpr operator -(ReqlExpr a, ReqlExpr b)
|
||||
{
|
||||
return a.sub(b);
|
||||
}
|
||||
|
||||
public static ReqlExpr operator *(ReqlExpr a, ReqlExpr b)
|
||||
{
|
||||
return a.mul(b);
|
||||
}
|
||||
|
||||
public static ReqlExpr operator /(ReqlExpr a, ReqlExpr b)
|
||||
{
|
||||
return a.div(b);
|
||||
}
|
||||
|
||||
public static ReqlExpr operator %(ReqlExpr a, ReqlExpr b)
|
||||
{
|
||||
return a.mod(b);
|
||||
}
|
||||
|
||||
public static ReqlExpr operator !(ReqlExpr a)
|
||||
{
|
||||
return a.not();
|
||||
}
|
||||
|
||||
|
||||
//&& and || might be a bit tricky here.
|
||||
public static bool operator false(ReqlExpr a)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool operator true(ReqlExpr a)
|
||||
{
|
||||
return false; //forces evaluation of & and | ?
|
||||
//this might be a bug here.
|
||||
}
|
||||
|
||||
public static ReqlExpr operator &(ReqlExpr a, ReqlExpr b)
|
||||
{
|
||||
return a.and(b);
|
||||
}
|
||||
|
||||
public static ReqlExpr operator |(ReqlExpr a, ReqlExpr b)
|
||||
{
|
||||
return a.or(b);
|
||||
}
|
||||
|
||||
|
||||
//Can we do implicit operators???
|
||||
public static implicit operator ReqlExpr(string a)
|
||||
{
|
||||
return Util.ToReqlExpr(a);
|
||||
}
|
||||
|
||||
public static implicit operator ReqlExpr(int a)
|
||||
{
|
||||
return Util.ToReqlExpr(a);
|
||||
}
|
||||
|
||||
public static implicit operator ReqlExpr(uint a)
|
||||
{
|
||||
return Util.ToReqlExpr(a);
|
||||
}
|
||||
|
||||
public static implicit operator ReqlExpr(byte a)
|
||||
{
|
||||
return Util.ToReqlExpr(a);
|
||||
}
|
||||
|
||||
public static implicit operator ReqlExpr(sbyte a)
|
||||
{
|
||||
return Util.ToReqlExpr(a);
|
||||
}
|
||||
|
||||
public static implicit operator ReqlExpr(long a)
|
||||
{
|
||||
return Util.ToReqlExpr(a);
|
||||
}
|
||||
|
||||
public static implicit operator ReqlExpr(ulong a)
|
||||
{
|
||||
return Util.ToReqlExpr(a);
|
||||
}
|
||||
|
||||
public static implicit operator ReqlExpr(double a)
|
||||
{
|
||||
return Util.ToReqlExpr(a);
|
||||
}
|
||||
|
||||
public static implicit operator ReqlExpr(decimal a)
|
||||
{
|
||||
return Util.ToReqlExpr(a);
|
||||
}
|
||||
|
||||
public static implicit operator ReqlExpr(float a)
|
||||
{
|
||||
return Util.ToReqlExpr(a);
|
||||
}
|
||||
|
||||
public static implicit operator ReqlExpr(DateTime a)
|
||||
{
|
||||
return Util.ToReqlExpr(a);
|
||||
}
|
||||
|
||||
public static implicit operator ReqlExpr(DateTimeOffset a)
|
||||
{
|
||||
return Util.ToReqlExpr(a);
|
||||
}
|
||||
|
||||
public static implicit operator ReqlExpr(Delegate a)
|
||||
{
|
||||
return Util.ToReqlExpr(a);
|
||||
}
|
||||
|
||||
public string ToRawString()
|
||||
{
|
||||
return ReqlRaw.ToRawString(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 32b53a1e5fbf70e48bd6200f09e30341
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,116 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using RethinkDb.Driver.Model;
|
||||
using RethinkDb.Driver.Proto;
|
||||
|
||||
namespace RethinkDb.Driver.Ast
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to inject raw protocol strings when the AST is dumped on the wire.
|
||||
/// </summary>
|
||||
public class ReqlRawExpr : ReqlExpr
|
||||
{
|
||||
private string RawProtocol { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Create an AST mid-flight with the raw protocol string.
|
||||
/// </summary>
|
||||
/// <param name="rawProtocol">Raw protocol string from ReqlAst.Build()</param>
|
||||
internal ReqlRawExpr(string rawProtocol) : base(new TermType(), null, null)
|
||||
{
|
||||
this.RawProtocol = rawProtocol;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the JToken representation of the raw protocol
|
||||
/// </summary>
|
||||
protected internal override object Build()
|
||||
{
|
||||
return JToken.Parse(this.RawProtocol);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to inject raw protocol strings when the AST is dumped on the wire.
|
||||
/// </summary>
|
||||
public class ReqlRaw : ReqlAst
|
||||
{
|
||||
private string RawProtocol { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Create an AST mid-flight with the raw protocol string.
|
||||
/// </summary>
|
||||
/// <param name="rawProtocol">Raw protocol string from ReqlAst.Build()</param>
|
||||
internal ReqlRaw(string rawProtocol) : base(new TermType(), null, null)
|
||||
{
|
||||
this.RawProtocol = rawProtocol;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the JToken representation of the raw protocol
|
||||
/// </summary>
|
||||
protected internal override object Build()
|
||||
{
|
||||
return JToken.Parse(this.RawProtocol);
|
||||
}
|
||||
|
||||
private const string RawTokenType = "$reql_reqlraw$";
|
||||
|
||||
/// <summary>
|
||||
/// Convert an AST item into a raw protocol string representation.
|
||||
/// Useful for serialization.
|
||||
/// </summary>
|
||||
/// <param name="astItem">Can be anything, ReqlFunction or otherwise</param>
|
||||
public static string ToRawString(object astItem)
|
||||
{
|
||||
var list = new List<Guid>();
|
||||
var token = Util.ToReqlAst(astItem, o => HookFuncTypes(o, list)).Build() as JToken;
|
||||
var query = token.ToString(Formatting.None);
|
||||
//pack
|
||||
return $"{string.Join("|", list)}{RawTokenType}{query}";
|
||||
}
|
||||
|
||||
internal static string HydrateProtocolString(string reqlRawString)
|
||||
{
|
||||
var tokenLocation = reqlRawString.IndexOf(RawTokenType, StringComparison.Ordinal);
|
||||
var guidStrings = reqlRawString.Substring(0, tokenLocation);
|
||||
var query = reqlRawString.Substring(tokenLocation + RawTokenType.Length);
|
||||
|
||||
//unpack
|
||||
var replaceTokens = guidStrings.Split('|')
|
||||
.Select(g => new { GuidString = $@"""{g}""", VarId = Func.NextVarId() });
|
||||
|
||||
foreach (var token in replaceTokens)
|
||||
{
|
||||
query = query.Replace(token.GuidString, token.VarId.ToString());
|
||||
}
|
||||
return query;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert a raw protocol string into an AST term that will
|
||||
/// be injected when the AST is serialized.
|
||||
/// </summary>
|
||||
/// <param name="reqlRawString">The raw protocol string to inject</param>
|
||||
/// <returns>A raw AST term</returns>
|
||||
public static ReqlRaw FromRawString(string reqlRawString)
|
||||
{
|
||||
var query = HydrateProtocolString(reqlRawString);
|
||||
return new ReqlRaw(query);
|
||||
}
|
||||
|
||||
|
||||
private static ReqlAst HookFuncTypes(object val, List<Guid> context)
|
||||
{
|
||||
var del = val as Delegate;
|
||||
if( del != null )
|
||||
{
|
||||
return Func.Serialize(del, context);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 97581729a9e4faf43bd2272864fd6bc7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System;
|
||||
using RethinkDb.Driver.Net.JsonConverters;
|
||||
|
||||
namespace RethinkDb.Driver.Ast
|
||||
{
|
||||
public partial class TopLevel
|
||||
{
|
||||
/// <summary>
|
||||
/// Type-safe helper method for R.Iso8601
|
||||
/// </summary>
|
||||
public Iso8601 Iso8601(DateTime? datetime)
|
||||
{
|
||||
var str = datetime?.ToString("o");
|
||||
return Ast.Iso8601.FromString(str);
|
||||
}
|
||||
/// <summary>
|
||||
/// Type-safe helper method for R.Iso8601
|
||||
/// </summary>
|
||||
public Iso8601 Iso8601(DateTimeOffset? datetime)
|
||||
{
|
||||
var str = datetime?.ToString("o");
|
||||
return Ast.Iso8601.FromString(str);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Type-safe helper for R.EpochTime
|
||||
/// </summary>
|
||||
public EpochTime EpochTime(DateTime? datetime)
|
||||
{
|
||||
var ticks = datetime?.ToUniversalTime().Ticks;
|
||||
var epoch = ReqlDateTimeConverter.ToUnixTime(ticks.Value);
|
||||
return EpochTime(epoch);
|
||||
}
|
||||
/// <summary>
|
||||
/// Type-safe helper for R.EpochTime
|
||||
/// </summary>
|
||||
public EpochTime EpochTime(DateTimeOffset? datetime)
|
||||
{
|
||||
var ticks = datetime?.UtcTicks;
|
||||
var epoch = ReqlDateTimeConverter.ToUnixTime(ticks.Value);
|
||||
return EpochTime(epoch);
|
||||
}
|
||||
|
||||
public ReqlRawExpr FromRawString(string reqlRawString)
|
||||
{
|
||||
var rawProtocol = ReqlRaw.HydrateProtocolString(reqlRawString);
|
||||
return new ReqlRawExpr(rawProtocol);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d17489d39926b8b4096c3d0f3d00600c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,142 +0,0 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using RethinkDb.Driver.Model;
|
||||
|
||||
namespace RethinkDb.Driver.Ast
|
||||
{
|
||||
internal static class Util
|
||||
{
|
||||
public static ReqlAst ToReqlAst(object val)
|
||||
{
|
||||
return ToReqlAst(val, 100, null);
|
||||
}
|
||||
public static ReqlAst ToReqlAst(object val, Func<object, ReqlAst> hook)
|
||||
{
|
||||
return ToReqlAst(val, 100, hook);
|
||||
}
|
||||
|
||||
public static ReqlExpr ToReqlExpr(object val)
|
||||
{
|
||||
var converted = ToReqlAst(val);
|
||||
var reqlAst = converted as ReqlExpr;
|
||||
if( !ReferenceEquals(reqlAst, null) )
|
||||
{
|
||||
return reqlAst;
|
||||
}
|
||||
throw new ReqlDriverError($"Cannot convert {val} to ReqlExpr");
|
||||
}
|
||||
|
||||
private static ReqlAst ToReqlAst(object val, int remainingDepth, Func<object, ReqlAst> hook = null )
|
||||
{
|
||||
if( remainingDepth <= 0 )
|
||||
{
|
||||
throw new ReqlDriverCompileError("Recursion limit reached converting to ReqlAst");
|
||||
}
|
||||
if( hook != null )
|
||||
{
|
||||
var converted = hook(val);
|
||||
if( !ReferenceEquals(converted, null) )
|
||||
{
|
||||
return converted;
|
||||
}
|
||||
}
|
||||
var ast = val as ReqlAst;
|
||||
if( !ReferenceEquals(ast, null) )
|
||||
{
|
||||
return ast;
|
||||
}
|
||||
|
||||
if( val is JToken token )
|
||||
{
|
||||
return new Poco(token);
|
||||
}
|
||||
|
||||
if( val is IList lst )
|
||||
{
|
||||
Arguments innerValues = new Arguments();
|
||||
foreach( object innerValue in lst )
|
||||
{
|
||||
innerValues.Add(ToReqlAst(innerValue, remainingDepth - 1));
|
||||
}
|
||||
return new MakeArray(innerValues, null);
|
||||
}
|
||||
|
||||
if( val is IDictionary dict )
|
||||
{
|
||||
var obj = new Dictionary<string, ReqlAst>();
|
||||
foreach( var keyObj in dict.Keys )
|
||||
{
|
||||
var key = keyObj as string;
|
||||
if( key == null )
|
||||
{
|
||||
throw new ReqlDriverCompileError("Object keys can only be strings");
|
||||
}
|
||||
|
||||
obj[key] = ToReqlAst(dict[keyObj]);
|
||||
}
|
||||
return MakeObj.fromMap(obj);
|
||||
}
|
||||
|
||||
if( val is Delegate del )
|
||||
{
|
||||
return Func.FromLambda(del);
|
||||
}
|
||||
|
||||
var dt = val as DateTime?;
|
||||
if( dt != null )
|
||||
{
|
||||
return new Poco(dt);
|
||||
}
|
||||
var dto = val as DateTimeOffset?;
|
||||
if( dto != null )
|
||||
{
|
||||
return new Poco(dto);
|
||||
}
|
||||
|
||||
var @int = val as int?;
|
||||
if( @int != null )
|
||||
{
|
||||
return new Datum(@int);
|
||||
}
|
||||
|
||||
if( IsNumber(val) )
|
||||
{
|
||||
return new Datum(val);
|
||||
}
|
||||
|
||||
var @bool = val as bool?;
|
||||
if( @bool != null )
|
||||
{
|
||||
return new Datum(@bool);
|
||||
}
|
||||
|
||||
if( val is string str )
|
||||
{
|
||||
return new Datum(str);
|
||||
}
|
||||
if( val == null )
|
||||
{
|
||||
return new Datum(null);
|
||||
}
|
||||
|
||||
return new Poco(val);
|
||||
}
|
||||
|
||||
public static bool IsNumber(object value)
|
||||
{
|
||||
return value is sbyte
|
||||
|| value is byte //maybe have char here?
|
||||
|| value is short
|
||||
|| value is ushort
|
||||
|| value is int
|
||||
|| value is uint
|
||||
|| value is long
|
||||
|| value is ulong
|
||||
|| value is float
|
||||
|| value is double
|
||||
|| value is decimal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 82410c8fb9920e940aa61c94125dd688
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,95 +0,0 @@
|
|||
using RethinkDb.Driver.Ast;
|
||||
using RethinkDb.Driver.Model;
|
||||
using RethinkDb.Driver.Proto;
|
||||
|
||||
namespace RethinkDb.Driver
|
||||
{
|
||||
internal class ErrorBuilder
|
||||
{
|
||||
internal string Msg { get; }
|
||||
internal ResponseType? ResponseType { get; }
|
||||
internal Backtrace Backtrace { get; set; }
|
||||
internal ErrorType? ErrorType { get; set; }
|
||||
internal ReqlAst Term { get; set; }
|
||||
|
||||
public ErrorBuilder(string msg, ResponseType responseType)
|
||||
{
|
||||
this.Msg = msg;
|
||||
this.ResponseType = responseType;
|
||||
}
|
||||
|
||||
public virtual ErrorBuilder SetBacktrace(Backtrace backtrace)
|
||||
{
|
||||
this.Backtrace = backtrace;
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual ErrorBuilder SetErrorType(ErrorType errorType)
|
||||
{
|
||||
this.ErrorType = errorType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual ErrorBuilder SetTerm(Query query)
|
||||
{
|
||||
this.Term = query.Term;
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual ReqlError Build()
|
||||
{
|
||||
ReqlError con;
|
||||
switch( ResponseType )
|
||||
{
|
||||
case Proto.ResponseType.CLIENT_ERROR:
|
||||
con = new ReqlClientError(Msg);
|
||||
break;
|
||||
case Proto.ResponseType.COMPILE_ERROR:
|
||||
con = new ReqlServerCompileError(Msg);
|
||||
break;
|
||||
case Proto.ResponseType.RUNTIME_ERROR:
|
||||
{
|
||||
switch( ErrorType )
|
||||
{
|
||||
case Proto.ErrorType.INTERNAL:
|
||||
con = new ReqlInternalError(Msg);
|
||||
break;
|
||||
case Proto.ErrorType.RESOURCE_LIMIT:
|
||||
con = new ReqlResourceLimitError(Msg);
|
||||
break;
|
||||
case Proto.ErrorType.QUERY_LOGIC:
|
||||
con = new ReqlQueryLogicError(Msg);
|
||||
break;
|
||||
case Proto.ErrorType.NON_EXISTENCE:
|
||||
con = new ReqlNonExistenceError(Msg);
|
||||
break;
|
||||
case Proto.ErrorType.OP_FAILED:
|
||||
con = new ReqlOpFailedError(Msg);
|
||||
break;
|
||||
case Proto.ErrorType.OP_INDETERMINATE:
|
||||
con = new ReqlOpIndeterminateError(Msg);
|
||||
break;
|
||||
case Proto.ErrorType.USER:
|
||||
con = new ReqlUserError(Msg);
|
||||
break;
|
||||
case Proto.ErrorType.PERMISSION_ERROR:
|
||||
con = new ReqlPermissionError(Msg);
|
||||
break;
|
||||
default:
|
||||
con = new ReqlRuntimeError(Msg);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
con = new ReqlError(Msg);
|
||||
break;
|
||||
}
|
||||
|
||||
con.Backtrace = this.Backtrace;
|
||||
con.Term = this.Term;
|
||||
|
||||
return con;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0c527493cc42ca048966cf4d2da9aed2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bdf576eeb0526ec4aad06928661a909c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 67b37b717eafc6542b57ccd0eb51a695
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
using Newtonsoft.Json;
|
||||
|
||||
namespace RethinkDb.Driver.Extras.Dao
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface for Document of IdT
|
||||
/// </summary>
|
||||
/// <typeparam name="IdT">Type of ID property</typeparam>
|
||||
public interface IDocument<IdT>
|
||||
{
|
||||
/// <summary>
|
||||
/// The Id of the document
|
||||
/// </summary>
|
||||
IdT Id { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// All Documents (aka. domain objects / entities) should derive from Document of IdT
|
||||
/// </summary>
|
||||
/// <typeparam name="IdT">Type of Id property</typeparam>
|
||||
public abstract class Document<IdT> : IDocument<IdT>
|
||||
{
|
||||
/// <summary>
|
||||
/// The Id of the document
|
||||
/// </summary>
|
||||
[JsonProperty("id",
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public virtual IdT Id { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 09071cad0d60ac147aa6867358676b9e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,84 +0,0 @@
|
|||
using System.Threading.Tasks;
|
||||
|
||||
namespace RethinkDb.Driver.Extras.Dao
|
||||
{
|
||||
/// <summary>
|
||||
/// Document Access Object interface
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Document entity</typeparam>
|
||||
/// <typeparam name="IdT">Type of Id property</typeparam>
|
||||
public interface IDao<T, IdT>
|
||||
{
|
||||
/// <summary>
|
||||
/// Get a document by Id.
|
||||
/// </summary>
|
||||
T GetById(IdT id);
|
||||
|
||||
/// <summary>
|
||||
/// Get a document by Id.
|
||||
/// </summary>
|
||||
Task<T> GetByIdAsync(IdT id);
|
||||
|
||||
///// <summary>
|
||||
///// Get all documents by Id
|
||||
///// </summary>
|
||||
///// <param name="ids">The Ids of the documents</param>
|
||||
//IEnumerable<T> GetAllById(params IdT[] ids);
|
||||
|
||||
/// <summary>
|
||||
/// Save document. If the document exists, an exception will be thrown. Returns and deserializes the returned document.
|
||||
/// </summary>
|
||||
/// <returns>Returns and deserializes the returned document</returns>
|
||||
T Save(T doc);
|
||||
|
||||
/// <summary>
|
||||
/// Save document. If the document exists, an exception will be thrown. Returns and deserializes the returned document.
|
||||
/// </summary>
|
||||
/// <returns>Returns and deserializes the returned document</returns>
|
||||
Task<T> SaveAsync(T doc);
|
||||
|
||||
/// <summary>
|
||||
/// Updates an existing document. If the document does not exist, an exception will be thrown.
|
||||
/// </summary>
|
||||
void Update(T doc);
|
||||
|
||||
/// <summary>
|
||||
/// Updates an existing document. If the document does not exist, an exception will be thrown.
|
||||
/// </summary>
|
||||
Task UpdateAsync(T doc);
|
||||
|
||||
/// <summary>
|
||||
/// Saves or updates a document. If the document doesn't exist, it will be saved. If the document exists, it will be updated.
|
||||
/// </summary>
|
||||
/// <param name="doc"></param>
|
||||
T SaveOrUpdate(T doc);
|
||||
|
||||
/// <summary>
|
||||
/// Saves or updates a document. If the document doesn't exist, it will be saved. If the document exists, it will be updated.
|
||||
/// </summary>
|
||||
/// <param name="doc"></param>
|
||||
Task<T> SaveOrUpdateAsync(T doc);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a document.
|
||||
/// </summary>
|
||||
void Delete(T doc);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a document.
|
||||
/// </summary>
|
||||
Task DeleteAsync(T doc);
|
||||
|
||||
/// <summary>
|
||||
/// Delete a document by Id.
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
void DeleteById(IdT id);
|
||||
|
||||
/// <summary>
|
||||
/// Delete a document by Id.
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
Task DeleteByIdAsync(IdT id);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b2c7d437869a40c418b05f65cff8eb6f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,209 +0,0 @@
|
|||
using System.Threading.Tasks;
|
||||
using RethinkDb.Driver.Ast;
|
||||
using RethinkDb.Driver.Model;
|
||||
using RethinkDb.Driver.Net;
|
||||
using RethinkDb.Driver.Utils;
|
||||
|
||||
namespace RethinkDb.Driver.Extras.Dao
|
||||
{
|
||||
/// <summary>
|
||||
/// Generic Document Access Object for RethinkDB
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of Document (aka. domain object / entity)</typeparam>
|
||||
/// <typeparam name="IdT">The type of the Id property in Document</typeparam>
|
||||
public abstract class RethinkDao<T, IdT> : IDao<T, IdT> where T : IDocument<IdT>
|
||||
{
|
||||
/// <summary>
|
||||
/// RethinkDB query root.
|
||||
/// </summary>
|
||||
protected static readonly RethinkDB R = RethinkDB.R;
|
||||
/// <summary>
|
||||
/// RethinkDB connection
|
||||
/// </summary>
|
||||
protected readonly IConnection conn;
|
||||
/// <summary>
|
||||
/// RethinkDB database name
|
||||
/// </summary>
|
||||
protected readonly string DbName;
|
||||
/// <summary>
|
||||
/// RethinkDB table name
|
||||
/// </summary>
|
||||
protected readonly string TableName;
|
||||
/// <summary>
|
||||
/// Table AST term used to build queries stating at the table term.
|
||||
/// </summary>
|
||||
protected readonly Table Table;
|
||||
|
||||
private readonly object returnChanges;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for <see cref="RethinkDao{T,IdT}"/>
|
||||
/// </summary>
|
||||
/// <param name="conn">The connection</param>
|
||||
/// <param name="dbName">The database</param>
|
||||
/// <param name="tableName">The table</param>
|
||||
protected RethinkDao(IConnection conn, string dbName, string tableName)
|
||||
{
|
||||
this.conn = conn;
|
||||
this.DbName = dbName;
|
||||
this.TableName = tableName;
|
||||
this.Table = R.Db(dbName).Table(tableName);
|
||||
|
||||
this.returnChanges = new { return_changes = true};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a document by Id.
|
||||
/// </summary>
|
||||
public virtual T GetById(IdT id)
|
||||
{
|
||||
return GetByIdAsync(id).WaitSync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a document by Id.
|
||||
/// </summary>
|
||||
public virtual Task<T> GetByIdAsync(IdT id)
|
||||
{
|
||||
return this.Table.Get(id).RunAtomAsync<T>(conn);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Save document. If the document exists, an exception will be thrown. Returns and deserializes the returned document.
|
||||
/// </summary>
|
||||
/// <returns>Returns and deserializes the returned document</returns>
|
||||
public virtual T Save(T doc)
|
||||
{
|
||||
return SaveAsync(doc).WaitSync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Save document. If the document exists, an exception will be thrown. Returns and deserializes the returned document.
|
||||
/// </summary>
|
||||
/// <returns>Returns and deserializes the returned document</returns>
|
||||
public virtual async Task<T> SaveAsync(T doc)
|
||||
{
|
||||
var result = await this.Table
|
||||
.Insert(doc)[returnChanges].OptArg("conflict", "error")
|
||||
.RunWriteAsync(conn)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
result.AssertNoErrors();
|
||||
result.AssertInserted(1);
|
||||
return result.ChangesAs<T>()[0].NewValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates an existing document. If the document does not exist, an exception will be thrown.
|
||||
/// </summary>
|
||||
public virtual void Update(T doc)
|
||||
{
|
||||
//var result = this.Table
|
||||
// .Get(doc.Id)
|
||||
// .Update(doc)
|
||||
// .RunResult(conn);
|
||||
|
||||
//var result = this.Table
|
||||
// .Replace(doc)
|
||||
// .RunResult(conn);
|
||||
|
||||
//var result = this.Table
|
||||
// .Get(doc.Id)
|
||||
// .Replace(dbDoc =>
|
||||
// R.Branch(dbDoc == null,
|
||||
// R.Error("The document doesn't exist"),
|
||||
// doc
|
||||
// )).RunResult(conn);
|
||||
|
||||
UpdateAsync(doc).WaitSync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates an existing document. If the document does not exist, an exception will be thrown.
|
||||
/// </summary>
|
||||
public virtual async Task UpdateAsync(T doc)
|
||||
{
|
||||
var result = await this.Table
|
||||
.GetAll(doc.Id).OptArg("index", "id")
|
||||
.Replace(doc)
|
||||
.RunWriteAsync(conn)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
result.AssertNoErrors();
|
||||
result.AssertReplaced(1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves or updates a document. If the document doesn't exist, it will be saved. If the document exists, it will be updated.
|
||||
/// </summary>
|
||||
/// <param name="doc"></param>
|
||||
public virtual T SaveOrUpdate(T doc)
|
||||
{
|
||||
return SaveOrUpdateAsync(doc).WaitSync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves or updates a document. If the document doesn't exist, it will be saved. If the document exists, it will be updated.
|
||||
/// </summary>
|
||||
/// <param name="doc"></param>
|
||||
public virtual async Task<T> SaveOrUpdateAsync(T doc)
|
||||
{
|
||||
var result = await this.Table
|
||||
.Insert(doc)[returnChanges].OptArg("conflict", "replace")
|
||||
.RunWriteAsync(conn)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
result.AssertNoErrors();
|
||||
|
||||
if (result.Inserted != 0)
|
||||
{
|
||||
result.AssertInserted(1);
|
||||
return result.ChangesAs<T>()[0].NewValue;
|
||||
}
|
||||
if (result.Replaced != 0)
|
||||
{
|
||||
result.AssertReplaced(1);
|
||||
return result.ChangesAs<T>()[0].NewValue;
|
||||
}
|
||||
throw new ReqlAssertFailure($"{nameof(SaveOrUpdate)} failed.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a document.
|
||||
/// </summary>
|
||||
public virtual void Delete(T doc)
|
||||
{
|
||||
DeleteAsync(doc).WaitSync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a document.
|
||||
/// </summary>
|
||||
public virtual Task DeleteAsync(T doc)
|
||||
{
|
||||
return DeleteByIdAsync(doc.Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete a document by Id.
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
public virtual void DeleteById(IdT id)
|
||||
{
|
||||
DeleteByIdAsync(id).WaitSync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete a document by Id.
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
public virtual async Task DeleteByIdAsync(IdT id)
|
||||
{
|
||||
var result = await this.Table.Get(id).Delete()
|
||||
.RunWriteAsync(conn)
|
||||
.ConfigureAwait(false);
|
||||
result.AssertDeleted(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 45ae3fa4f7844354da676c3514ffd884
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue