예제 #1
0
        public JsonLocatorField(string dataLocator, StoreOptions options, EnumStorage enumStyle, Casing casing, MemberInfo[] members, string pgType = null) : base(enumStyle, members)
        {
            var locator = CommandBuilder.BuildJsonStringLocator(dataLocator, members, casing);

            var isStringEnum = MemberType.IsEnum && enumStyle == EnumStorage.AsString;

            if (!string.IsNullOrWhiteSpace(pgType))
            {
                PgType = pgType;
            }

            if (MemberType == typeof(string) || isStringEnum)
            {
                SqlLocator = $"{locator}";
            }
            else if (TypeMappings.TimespanTypes.Contains(MemberType))
            {
                SqlLocator       = $"{options?.DatabaseSchemaName ?? StoreOptions.DefaultDatabaseSchemaName}.mt_immutable_timestamp({locator})";
                SelectionLocator = $"CAST({locator} as {PgType})";
            }
            else if (TypeMappings.TimespanZTypes.Contains(MemberType))
            {
                SqlLocator       = $"{options?.DatabaseSchemaName ?? StoreOptions.DefaultDatabaseSchemaName}.mt_immutable_timestamptz({locator})";
                SelectionLocator = $"CAST({locator} as {PgType})";
            }
            else if (MemberType.IsArray)
            {
                SqlLocator = $"CAST({locator} as jsonb)";
            }
            else
            {
                SqlLocator = $"CAST({locator} as {PgType})";
            }

            if (isStringEnum)
            {
                _parseObject = expression =>
                {
                    var raw = expression.Value();
                    return(Enum.GetName(MemberType, raw));
                };
            }

            if (SelectionLocator.IsEmpty())
            {
                SelectionLocator = SqlLocator;
            }
        }
예제 #2
0
        public JsonLocatorField(string dataLocator, StoreOptions options, EnumStorage enumStyle, Casing casing, MemberInfo member) : base(enumStyle, member)
        {
            var memberType = member.GetMemberType();
            var memberName = member.Name.FormatCase(casing);

            var isStringEnum = memberType.IsEnum && enumStyle == EnumStorage.AsString;

            if (memberType == typeof(string) || isStringEnum)
            {
                SqlLocator = $"{dataLocator} ->> '{memberName}'";
            }
            else if (TypeMappings.TimespanTypes.Contains(memberType))
            {
                SqlLocator       = $"{options.DatabaseSchemaName}.mt_immutable_timestamp({dataLocator} ->> '{memberName}')";
                SelectionLocator = $"CAST({dataLocator} ->> '{memberName}' as {PgType})";
            }
            else if (TypeMappings.TimespanZTypes.Contains(memberType))
            {
                SqlLocator       = $"{options.DatabaseSchemaName}.mt_immutable_timestamptz({dataLocator} ->> '{memberName}')";
                SelectionLocator = $"CAST({dataLocator} ->> '{memberName}' as {PgType})";
            }
            else if (memberType.IsArray)
            {
                SqlLocator = $"CAST({dataLocator} ->> '{memberName}' as jsonb)";
            }
            else
            {
                SqlLocator = $"CAST({dataLocator} ->> '{memberName}' as {PgType})";
            }

            if (isStringEnum)
            {
                _parseObject = expression =>
                {
                    var raw = expression.Value();
                    return(Enum.GetName(MemberType, raw));
                };
            }

            if (SelectionLocator.IsEmpty())
            {
                SelectionLocator = SqlLocator;
            }
        }
예제 #3
0
        public JsonLocatorField(StoreOptions options, EnumStorage enumStyle, MemberInfo member) : base(member)
        {
            var memberType = member.GetMemberType();

            var isStringEnum = memberType.GetTypeInfo().IsEnum&& enumStyle == EnumStorage.AsString;

            if (memberType == typeof(string) || isStringEnum)
            {
                SqlLocator = $"d.data ->> '{member.Name}'";
            }
            else if (memberType == typeof(DateTime) || memberType == typeof(DateTime?))
            {
                SqlLocator       = $"{options.DatabaseSchemaName}.mt_immutable_timestamp(d.data ->> '{member.Name}')";
                SelectionLocator = $"CAST(d.data ->> '{member.Name}' as {PgType})";
            }
            else if (memberType == typeof(DateTimeOffset) || memberType == typeof(DateTimeOffset?))
            {
                SqlLocator       = $"{options.DatabaseSchemaName}.mt_immutable_timestamp(d.data ->> '{member.Name}')";
                SelectionLocator = $"CAST(d.data ->> '{member.Name}' as {PgType})";
            }
            else
            {
                SqlLocator = $"CAST(d.data ->> '{member.Name}' as {PgType})";
            }

            if (isStringEnum)
            {
                _parseObject = expression =>
                {
                    var raw = expression.Value();
                    return(Enum.GetName(MemberType, raw));
                };
            }

            if (SelectionLocator.IsEmpty())
            {
                SelectionLocator = SqlLocator;
            }
        }