コード例 #1
0
        public UpdateStatementsBuilder <TModel> AddToList <TValue>(Expression <Func <TModel, IList <TValue> > > field, TValue value, UpdateAddToListFlags flags = UpdateAddToListFlags.None)
        {
            var pi = NodeVisitor.VisitPath(field, null);

            if (pi.Expression.Type is KDPgValueTypeArray)
            {
                if ((flags & UpdateAddToListFlags.Distinct) == UpdateAddToListFlags.None)
                {
                    AddUpdate(pi.Column, src => ExpressionBuilders.ArrayAddItem(src, value));
                }
                else
                {
                    AddUpdate(pi.Column, src => ExpressionBuilders.KDPgArrayDistinct(ExpressionBuilders.ArrayAddItem(src, value)));
                }
            }
            else if (pi.Expression.Type is KDPgValueTypeJson)
            {
                if (flags != 0)
                {
                    throw new Exception("flags not allowed on json array");
                }

                AddUpdate(pi.Column, src => ExpressionBuilders.KDPgJsonbAdd(src, pi.JsonPath, value));
            }
            else
            {
                throw new Exception("unable to add to non-list");
            }

            return(this);
        }
コード例 #2
0
    public static WhereBuilder<TModel> Eq<T>(Expression<Func<TModel, T>> field, T value)
    {
      var column = NodeVisitor.EvaluateExpressionToColumn(field.Body);
      var pgValue = PgTypesConverter.ConvertObjectToPgValue(value);

      var right = TypedExpression.FromPgValue(pgValue);

      return new WhereBuilder<TModel>(ExpressionBuilders.Eq(column.TypedExpression, right));
    }
コード例 #3
0
        public UpdateStatementsBuilder <TModel> SetField <TValue>(Expression <Func <TModel, TValue> > field, TValue value)
        {
            var pi       = NodeVisitor.VisitPath(field, null);
            var npgValue = PgTypesConverter.ConvertToPgValue(pi.Expression.Type, value);

            if (pi.JsonPath.Count > 0)
            {
                AddUpdate(pi.Column, src => ExpressionBuilders.JsonSet(src, pi.JsonPath, TypedExpression.FromPgValue(npgValue)));
            }
            else
            {
                AddUpdate(pi.Column, src => TypedExpression.FromPgValue(npgValue));
            }

            return(this);
        }
コード例 #4
0
        public UpdateStatementsBuilder <TModel> RemoveAllFromList <TValue>(Expression <Func <TModel, IList <TValue> > > field, TValue value)
        {
            var pi = NodeVisitor.VisitPath(field, null);

            if (pi.Expression.Type is KDPgValueTypeArray)
            {
                AddUpdate(pi.Column, src => ExpressionBuilders.ArrayRemoveItem(src, value));
            }
            else if (pi.Expression.Type is KDPgValueTypeJson)
            {
                AddUpdate(pi.Column, src => ExpressionBuilders.KDPgJsonbRemoveByValue(src, pi.JsonPath, value, false));
            }
            else
            {
                throw new Exception("unable to add to non-list");
            }

            return(this);
        }
コード例 #5
0
 public static WhereBuilder<TModel> Or(params WhereBuilder<TModel>[] statements)
 {
   return new WhereBuilder<TModel>(ExpressionBuilders.Or(statements.Select(x => x._typedExpression)));
 }
コード例 #6
0
 public static WhereBuilder<TModel> ContainsAny<T>(Expression<Func<TModel, IList<T>>> field, IEnumerable<T> array)
 {
   var column = NodeVisitor.EvaluateExpressionToColumn(field.Body);
   return new WhereBuilder<TModel>(ExpressionBuilders.ContainsAny(column.TypedExpression, array));
 }
コード例 #7
0
 public static WhereBuilder<TModel> ContainsAny<T>(Expression<Func<TModel, IList<T>>> field, params T[] values)
 {
   var column = NodeVisitor.EvaluateExpressionToColumn(field.Body);
   return new WhereBuilder<TModel>(ExpressionBuilders.ContainsAny(column.TypedExpression, values));
 }
コード例 #8
0
 public static WhereBuilder<TModel> In<T>(Expression<Func<TModel, T>> field, SelectSubquery<T> subquery)
 {
   var column = NodeVisitor.EvaluateExpressionToColumn(field.Body);
   return new WhereBuilder<TModel>(ExpressionBuilders.In(column.TypedExpression, subquery.GetTypedExpression()));
 }
コード例 #9
0
 public static WhereBuilder<TModel> Not(WhereBuilder<TModel> statement)
 {
   return new WhereBuilder<TModel>(ExpressionBuilders.Not(statement._typedExpression));
 }