示例#1
0
        protected DdbConverter <TProperty> GetPropertyConverter <TProperty>(DdbExpressionVisitor visitor)
        {
            return((DdbConverter <TProperty>)visitor.ClassInfo.ConverterBase);

            // var propertyName = visitor.CachedAttributeNames[^1];
            // if (!visitor.ClassInfo.PropertiesMap.TryGetValue(propertyName, out var propertyInfo))
            //     throw new DdbException(
            //         $"Property {propertyName} does not exist in entity {visitor.ClassInfo.Type.Name} or it's not marked by {nameof(DynamoDbPropertyAttribute)} attribute");
            //
            // return ((DdbPropertyInfo<TProperty>) propertyInfo).Converter;
        }
示例#2
0
        internal override void WriteExpressionStatement(ref NoAllocStringBuilder builder, ref int valuesCount, DdbExpressionVisitor visitor)
        {
            // "#a = :v0"

            visitor.Visit <TEntity>(Expression);

            WriteEncodedExpressionName(visitor.Builder, _useSize, ref builder);
            builder.Append(" = :v");
            builder.Append(valuesCount++);
        }
示例#3
0
        internal override void WriteExpressionStatement(ref NoAllocStringBuilder builder, ref int valuesCount, DdbExpressionVisitor visitor)
        {
            // "SET #a = #b + #c"

            visitor.Visit <TEntity>(Expression);
            builder.Append(visitor.Builder);

            builder.Append(" = ");

            visitor.Visit <TEntity>(_left);
            builder.Append(visitor.Builder);

            AppendMathOperatorExpression(ref builder);

            visitor.Visit <TEntity>(_right);
            builder.Append(visitor.Builder);
        }
示例#4
0
        internal override void WriteExpressionStatement(ref NoAllocStringBuilder builder, ref int valuesCount, DdbExpressionVisitor visitor)
        {
            // "#a IN (:v0, :v1, :v2)"

            visitor.Visit <TEntity>(Expression);

            WriteEncodedExpressionName(visitor.Builder, _useSize, ref builder);
            builder.Append(" IN (");

            for (var i = 0; i < _values.Length; i++)
            {
                if (i > 0)
                {
                    builder.Append(", ");
                }

                builder.Append(":v");
                builder.Append(valuesCount++);
            }

            builder.Append(')');
        }
示例#5
0
        internal override void WriteExpressionStatement(ref NoAllocStringBuilder builder, ref int valuesCount, DdbExpressionVisitor visitor)
        {
            // "SET #a = list_append(if_not_exists(#b, :v0),if_not_exists(#c, :v1))"

            visitor.Visit <TEntity>(Expression);
            builder.Append(visitor.Builder);

            builder.Append(" = list_append(");

            WriteIfNotExistsBlock <TEntity>(ref builder, visitor, _left, ref valuesCount);

            builder.Append(',');

            WriteIfNotExistsBlock <TEntity>(ref builder, visitor, _right, ref valuesCount);

            builder.Append(')');
        }
示例#6
0
        internal override void WriteExpressionStatement(ref NoAllocStringBuilder builder, ref int valuesCount, DdbExpressionVisitor visitor)
        {
            // "SET #a = #b + if_not_exists(#c, :v0)"

            visitor.Visit <TEntity>(Expression);
            builder.Append(visitor.Builder);

            builder.Append(" = ");

            visitor.Visit <TEntity>(_left);
            builder.Append(visitor.Builder);

            AppendMathOperatorExpression(ref builder);

            WriteIfNotExistsBlock <TEntity>(ref builder, visitor, _right, ref valuesCount);
        }
        internal override void WriteExpressionStatement(ref NoAllocStringBuilder builder, ref int valuesCount, DdbExpressionVisitor visitor)
        {
            // "SET #a = list_append(#b,#c)"

            visitor.Visit <TEntity>(Expression);
            builder.Append(visitor.Builder);

            builder.Append(" = list_append(");

            visitor.Visit <TEntity>(_left);
            builder.Append(visitor.Builder);

            builder.Append(',');

            visitor.Visit <TEntity>(_right);
            builder.Append(visitor.Builder);

            builder.Append(')');
        }
示例#8
0
 protected DdbConverter <TProperty> GetPropertyConverter <TProperty>(DdbExpressionVisitor visitor, bool useSize) =>
 useSize?visitor.Metadata.GetOrAddConverter <TProperty>() : (DdbConverter <TProperty>)visitor.ClassInfo.ConverterBase;
示例#9
0
 internal abstract void WriteExpressionStatement(ref NoAllocStringBuilder builder, ref int valuesCount, DdbExpressionVisitor visitor);
示例#10
0
        internal override void WriteExpressionStatement(ref NoAllocStringBuilder builder, ref int valuesCount, DdbExpressionVisitor visitor)
        {
            // "REMOVE #a"

            visitor.Visit <TEntity>(Expression);
            builder.Append(visitor.Builder);
        }
示例#11
0
        internal override void WriteExpressionStatement(ref NoAllocStringBuilder builder, ref int valuesCount, DdbExpressionVisitor visitor)
        {
            // attribute_not_exists(#a)

            visitor.Visit <TEntity>(Expression);

            builder.Append("attribute_not_exists(");
            builder.Append(visitor.Builder);
            builder.Append(')');
        }
        protected override ValueTask WriteDataAsync(DdbWriter writer)
        {
            writer.JsonWriter.WriteStartObject();

            var writeState        = 0;
            var projectionWritten = false;

            foreach (var node in _node)
            {
                switch (node.Type)
                {
                case BuilderNodeType.PrimaryKey:
                    ((PrimaryKeyNodeBase)node).Write(in writer, _classInfo, ref writeState);
                    break;

                case BuilderNodeType.ProjectedAttributes:
                    if (projectionWritten)
                    {
                        break;
                    }

                    // ReSharper disable once StackAllocInsideLoop
                    var builder = new NoAllocStringBuilder(stackalloc char[NoAllocStringBuilder.MaxStackAllocSize], true);

                    try
                    {
                        var visitor = new DdbExpressionVisitor(_context.Config.Metadata);

                        writer.JsonWriter.WriteProjectedAttributes(node, ref builder, visitor, _context.Config.Metadata);

                        if (visitor.CachedAttributeNames.Count > 0)
                        {
                            writer.JsonWriter.WriteExpressionAttributeNames(ref builder, visitor.CachedAttributeNames);
                        }

                        projectionWritten = true;
                    }
                    finally
                    {
                        builder.Dispose();
                    }

                    break;

                case BuilderNodeType.TableName:
                    ((TableNameNode)node).WriteTableName(in writer, ref writeState, _context.Config.TableNamePrefix);
                    break;

                default:
                    node.WriteValue(in writer, ref writeState);
                    break;
                }
            }

            if (!writeState.IsBitSet(NodeBits.TableName))
            {
                writer.JsonWriter.WriteTableName(_context.Config.TableNamePrefix, _classInfo.TableName !);
            }

            writer.JsonWriter.WriteEndObject();

            return(new ValueTask());
        }