Exemple #1
0
        /// <summary>
        /// Create a new instance of the <see cref="SqlJunctionConfigBuilder"/> configured for batching the many-to-many query.
        /// </summary>
        /// <param name="fieldType">The <see cref="FieldType"/>.</param>
        /// <param name="tableName">The junction table name.</param>
        /// <param name="uniqueKey">The unique key columns.</param>
        /// <param name="thisKey">The column to match on the current table.</param>
        /// <param name="parentKey">The column to match in the parent table.</param>
        /// <param name="join">The JOIN condition when joining from the junction table to the related table.</param>
        /// <returns>The <see cref="SqlJunctionConfigBuilder"/>.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="fieldType"/>, <paramref name="tableName"/>, <paramref name="uniqueKey"/>, <paramref name="thisKey"/>, <paramref name="parentKey"/> or <paramref name="join"/> is <c>null</c>.</exception>
        public static SqlJunctionConfigBuilder SqlJunction(this FieldType fieldType, string tableName, string[] uniqueKey, string thisKey, string parentKey, JoinDelegate join)
        {
            if (fieldType == null)
            {
                throw new ArgumentNullException(nameof(fieldType));
            }
            if (tableName == null)
            {
                throw new ArgumentNullException(nameof(tableName));
            }
            if (thisKey == null)
            {
                throw new ArgumentNullException(nameof(thisKey));
            }
            if (parentKey == null)
            {
                throw new ArgumentNullException(nameof(parentKey));
            }
            if (join == null)
            {
                throw new ArgumentNullException(nameof(join));
            }

            var builder = SqlJunctionConfigBuilder.Create(tableName, uniqueKey, thisKey, parentKey, join);

            fieldType.WithMetadata(nameof(SqlJunctionConfig), builder.SqlJunctionConfig);
            return(builder);
        }
Exemple #2
0
        public void Create_WithTableName_SetsTableName()
        {
            var tableName = "friends";
            var builder   =
                SqlJunctionConfigBuilder.Create(tableName, (_, __, ___, ____) => { }, (_, __, ___, ____) => { });

            builder.SqlJunctionConfig.Table.Should().Be(tableName);
        }
Exemple #3
0
        public void Create_WhenToChildIsNull_ThrowsException()
        {
            Action action = () => SqlJunctionConfigBuilder.Create("friends", (_, __, ___, ____) => { }, null);

            action.Should()
            .Throw <ArgumentNullException>()
            .Which.ParamName.Should()
            .Be("toChild");
        }
Exemple #4
0
        public void Create_WhenFromParentIsNull_ThrowsException()
        {
            Action action = () => SqlJunctionConfigBuilder.Create("friends", null, null);

            action.Should()
            .Throw <ArgumentNullException>()
            .Which.ParamName.Should()
            .Be("fromParent");
        }
Exemple #5
0
        public void Create_WhenTableNameIsNull_ThrowsException()
        {
            Action action = () => SqlJunctionConfigBuilder.Create(null, null, null);

            action.Should()
            .Throw <ArgumentNullException>()
            .Which.ParamName.Should()
            .Be("tableName");
        }
Exemple #6
0
        public void Create_WithToChild_SetsToChild()
        {
            void ToChild(JoinBuilder join, IReadOnlyDictionary <string, object> arguments,
                         IResolveFieldContext context, Node sqlAstNode)
            {
            }

            var builder =
                SqlJunctionConfigBuilder.Create("friends", (_, __, ___, ____) => { }, ToChild);

            builder.SqlJunctionConfig.ToChild.Should().Be((JoinDelegate)ToChild);
        }
Exemple #7
0
        public void Create_WithFromParent_SetsFromParent()
        {
            void FromParent(JoinBuilder join, IReadOnlyDictionary <string, object> arguments,
                            IResolveFieldContext context, Node sqlAstNode)
            {
            }

            var builder =
                SqlJunctionConfigBuilder.Create("friends", FromParent, (_, __, ___, ____) => { });

            builder.SqlJunctionConfig.FromParent.Should().Be((JoinDelegate)FromParent);
        }
Exemple #8
0
        public void Where_WithWhereCondition_SetsWhere()
        {
            void Where(WhereBuilder where, IReadOnlyDictionary <string, object> arguments,
                       IResolveFieldContext context, SqlTable sqlAStNode)
            {
            }

            var builder = SqlJunctionConfigBuilder.Create("friends", (_, __, ___, ____) => { }, (_, __, ___, ____) => { });

            builder.Where(Where);

            builder.SqlJunctionConfig.Where.Should().Be((WhereDelegate)Where);
        }
Exemple #9
0
        /// <summary>
        /// Configure a SQL Junction.
        /// </summary>
        /// <param name="fieldConfig">The field config.</param>
        /// <param name="tableName">The table name.</param>
        /// <param name="fromParent">The JOIN condition when joining from the parent table to the junction table.</param>
        /// <param name="toChild">The JOIN condition when joining from the junction table to the child table.</param>
        /// <returns>The <see cref="SqlJunctionConfigBuilder"/>.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="fieldConfig"/> is <c>null</c>.</exception>
        public static SqlJunctionConfigBuilder SqlJunction(this FieldConfig fieldConfig, string tableName, JoinDelegate fromParent, JoinDelegate toChild)
        {
            if (fieldConfig == null)
            {
                throw new ArgumentNullException(nameof(fieldConfig));
            }

            var builder = SqlJunctionConfigBuilder.Create(tableName, fromParent, toChild);

            fieldConfig.WithMetadata(nameof(SqlJunctionConfig), builder.SqlJunctionConfig);
            fieldConfig.Resolver ??= DictionaryFieldResolver.Instance;

            return(builder);
        }
Exemple #10
0
        public void Create_WithBatchConfiguration_SetsBatchConfig()
        {
            void Join(JoinBuilder join, IReadOnlyDictionary <string, object> _, IResolveFieldContext __, SqlTable ___)
            {
            }

            var builder = SqlJunctionConfigBuilder.Create("friends", new[] { "characterId", "friendId" }, "friendId", "id", Join);

            builder.SqlJunctionConfig.BatchConfig.Should()
            .BeEquivalentTo(new SqlBatchConfig("friendId", "id")
            {
                Join = Join
            });
        }