/// <summary> /// Appends the current property name, e.g. <c>"Item.MyValue"</c>, to the attribute buffer. /// </summary> /// <param name="attribute">The current attribute</param> /// <param name="tblAlias">An alias to qualify the property name with.</param> /// <param name="propName">A name to suffix the property name with.</param> /// <returns>A new attribute containing the appended buffer.</returns> public static IProjectionAttribute Prop(this IProjectionAttribute attribute, string tblAlias = null, string propName = null) { if (attribute.Metadata.HasFlag(RelationMetadataFlags.Model) && (propName == null || attribute.Data != null)) { throw ProjectionException.PropertyNotFound(attribute.Metadata); } if (attribute.Data != null) { ColumnBinding binding = new ColumnBinding(attribute.Data.Output); propName = attribute.Context.Domain.Dialect.Identifier(binding.ColumnName); return(attribute.Append(propName).Append(binding)); } else { string fullName = attribute.Metadata.Identity.Name; if (propName != null) { fullName = attribute.Identity.Schema.Notation.Combine(fullName, propName); } if (tblAlias != null) { attribute = attribute.Append(attribute.Context.Domain.Dialect.Identifier(tblAlias)); attribute = attribute.Append(attribute.Context.Domain.Dialect.Qualifier); } return(attribute.Append(attribute.Context.Domain.Dialect.Identifier(fullName))); } }
/// <summary> /// Appends the current parameter name and value, e.g. <c>@P0</c>, to the attribute buffer. /// </summary> /// <param name="attribute">The current attribute.</param> /// <returns>A new attribute containing the appended buffer.</returns> public static IProjectionAttribute Par(this IProjectionAttribute attribute) { if (!attribute.Context.Domain.Dialect.Support.HasFlag(DialectSupport.InputParameters)) { throw ProjectionException.FromProjection(attribute, $"Dialect '{attribute.Context.Domain.Dialect.GetType().Name}' does not support input parameters."); } IField value = attribute.Field?.Invoke(); if (value != null) { string paramName = attribute.Context.Lookup.Parameter(attribute.Identity, value); string dialectName = attribute.Context.Domain.Dialect.Parameter(paramName); Parameter param = new Parameter(paramName, value); IProjectionAttribute result = attribute.Append(dialectName).Append(param); if (attribute.Metadata.HasFlag(ProjectionMetadataFlags.Output) && attribute.Context.Domain.Dialect.Support.HasFlag(DialectSupport.OutputParameters)) { ParameterBinding binding = new ParameterBinding(param); result = result.Append(binding); } return(result); } else { string paramName = attribute.Context.Lookup.Parameter(attribute.Identity, attribute.Metadata.Identity); string dialectName = attribute.Context.Domain.Dialect.Parameter(paramName); return(attribute.Append(dialectName)); } }
/// <summary> /// Appends the current property name, e.g. <c>"Item.MyValue"</c>, to the attribute buffer. /// </summary> /// <param name="attribute">The current attribute</param> /// <param name="tblAlias">An alias to qualify the property name with.</param> /// <param name="propName">A name to suffix the property name with.</param> /// <returns>A new attribute containing the appended buffer.</returns> public static IProjectionAttribute Prop(this IProjectionAttribute attribute, string tblAlias = null, string propName = null) { if ((propName == null || attribute.Field != null) && attribute.Metadata.HasFlag(RelationMetadataFlags.Model)) { throw ProjectionException.FromProjection(attribute, "Cannot reference model directly."); } if (attribute.Field != null) { IField field = attribute.Field(); ColumnBinding binding = new ColumnBinding(field.Identity.Name, field); propName = attribute.Context.Domain.Dialect.Identifier(binding.ColumnName); return(attribute.Append(propName).Append(binding)); } else { string fullName = attribute.Metadata.Identity.Name; if (propName != null) { fullName = attribute.Identity.Schema.Notation.Combine(fullName, propName); } if (tblAlias != null) { attribute = attribute.Append(attribute.Context.Domain.Dialect.Identifier(tblAlias)); attribute = attribute.Append(attribute.Context.Domain.Dialect.Qualifier); } return(attribute.Append(attribute.Context.Domain.Dialect.Identifier(fullName))); } }
/// <summary> /// Appends the current parameter name and value, e.g. <c>@P0</c>, to the attribute buffer. /// </summary> /// <param name="attribute">The current attribute.</param> /// <returns>A new attribute containing the appended buffer.</returns> public static IProjectionAttribute Par(this IProjectionAttribute attribute) { IField value = attribute.Field?.Invoke(); if (value != null) { string paramName = attribute.Context.Lookup.Parameter(attribute.Identity, value); string dialectName = attribute.Context.Domain.Dialect.Parameter(paramName); Parameter param = new Parameter(paramName, value); IProjectionAttribute result = attribute.Append(dialectName).Append(param); if (attribute.Metadata.HasFlag(ProjectionMetadataFlags.Output)) { ParameterBinding binding = new ParameterBinding(param.Name, value); result = result.Append(binding); } return(result); } else { string paramName = attribute.Context.Lookup.Parameter(attribute.Identity, attribute.Metadata.Identity); string dialectName = attribute.Context.Domain.Dialect.Parameter(paramName); return(attribute.Append(dialectName)); } }
/// <summary> /// Appends the current column name in qualified form, e.g. <c>T0."MyColumn"</c>, to the attribute buffer. /// </summary> /// <param name="attribute">The current attribute.</param> /// <param name="tblAlias">The table alias to qualify the column name with.</param> /// <returns>A new attribute containing the appended buffer.</returns> public static IProjectionAttribute Col(this IProjectionAttribute attribute, string tblAlias = null) { if (tblAlias != null) { attribute = attribute.Append(attribute.Context.Domain.Dialect.Identifier(tblAlias)); } else { attribute = attribute.Ali(); } return(attribute.Append(attribute.Context.Domain.Dialect.Qualifier).ColName()); }
/// <summary> /// Appends a call to <c>JSON_EXTRACT</c> from the current column and JSON path, e.g. <c>JSON_EXTRACT(T0."MyJson", '$.my.value')</c>, to the attribute buffer. /// </summary> /// <param name="attribute">The current attribute.</param> /// <returns>A new attribute containing the appended buffer.</returns> public static IProjectionAttribute Json(this IProjectionAttribute attribute) { IJsonMetadata json = attribute.Metadata.Identity.Require <IJsonMetadata>(); IProjectionMetadata valueMetadata = attribute.Metadata; IProjectionMetadata rootMetadata = json.MemberOf.Identity.Lookup <IProjectionMetadata>(); attribute = attribute.Append("JSON_EXTRACT("); attribute = attribute.With(metadata: rootMetadata).Col(); attribute = attribute.Append(","); attribute = attribute.With(metadata: valueMetadata).JsonPath(); attribute = attribute.Append(")"); return(attribute); }
/// <summary> /// Appends the current column name in unqualified form, e.g. <c>"MyColumn"</c>, to the attribute buffer. /// </summary> /// <param name="attribute">The current attribute.</param> /// <returns>A new attribute containing the appended buffer.</returns> public static IProjectionAttribute ColName(this IProjectionAttribute attribute) { ITableMetadata column = ProjectionHelper.GetPreferredColumnMetadata(attribute); string identifier = attribute.Context.Domain.Dialect.Identifier(column.ColumnName); return(attribute.Append(identifier)); }
/// <summary> /// Appends the current table alias, e.g. <c>T0</c>, to the attribute buffer. /// </summary> /// <param name="attribute">The current attribute.</param> /// <returns>A new attribute containing the appended buffer.</returns> public static IProjectionAttribute Ali(this IProjectionAttribute attribute) { ITableMetadata table = ProjectionHelper.GetTableMetadata(attribute); string alias = attribute.Context.Lookup.Table(attribute.Identity, table.Identity); return(attribute.Append(alias)); }
/// <summary> /// Appends the current JSON path literal, e.g. <c>'$.my.value'</c>, to the attribute buffer. /// </summary> /// <param name="attribute">The current attribute.</param> /// <returns>A new attribute containing the appended buffer.</returns> public static IProjectionAttribute JsonPath(this IProjectionAttribute attribute) { IJsonMetadata metadata = ProjectionHelper.GetJsonMetadata(attribute.Metadata); string literal = attribute.Context.Domain.Dialect.String(metadata.Path); return(attribute.Append(literal)); }
public static IProjectionAttribute Refcursor(this IProjectionAttribute attribute) { string paramName = attribute.Context.Lookup.Custom("R", attribute.Identity, attribute.Metadata.Identity, attribute.Field?.Invoke()); string dialectName = attribute.Context.Domain.Dialect.Parameter(paramName); Parameter param = new Parameter(paramName, contract: new RefcursorContract()); return(attribute.Append(dialectName).Append(param)); }
public static IProjectionAttribute Refcursor(this IProjectionAttribute attribute) { string paramName = attribute.Context.Lookup.Custom("R"); string dialectName = attribute.Context.Domain.Dialect.Parameter(paramName); Refcursor param = new Refcursor(paramName); return(attribute.Append(dialectName).Append(param)); }
/// <summary> /// Appends the current table name, e.g. <c>"MyTable"</c>, to the attribute buffer. /// </summary> /// <param name="attribute">The current attribute.</param> /// <returns>A new attribute containing the appended buffer.</returns> public static IProjectionAttribute TblName(this IProjectionAttribute attribute) { ITableMetadata table = ProjectionHelper.GetTableMetadata(attribute); string qualifier = attribute.Context.Domain.Dialect.Qualifier; string tableName = string.Join(qualifier, table.TableName.Select(attribute.Context.Domain.Dialect.Identifier)); return(attribute.Append(tableName)); }
/// <summary> /// Appends the current variable name, e.g. <c>@V0</c>, to the attribute buffer. /// </summary> /// <param name="attribute">The current attribute.</param> /// <returns>A new attribute containing the appended buffer.</returns> public static IProjectionAttribute Var(this IProjectionAttribute attribute) { IField field = ProjectionHelper.GetFieldValue(attribute); string variableName = attribute.Context.Lookup.Variable(attribute.Identity, field); string dialectName = attribute.Context.Domain.Dialect.Variable(variableName); return(attribute.Append(dialectName)); }
/// <summary> /// Appends the current parameter name and value, e.g. <c>@P0</c>, to the attribute buffer. /// </summary> /// <param name="attribute">The current attribute.</param> /// <returns>A new attribute containing the appended buffer.</returns> public static IProjectionAttribute Par(this IProjectionAttribute attribute) { if (!attribute.Context.Domain.Dialect.Support.HasFlag(DialectSupport.InputParameters)) { throw ProjectionException.ParametersNotSupported(attribute); } if (attribute.Data?.Input != null) { string paramName = attribute.Context.Lookup.Parameter(attribute.Identity, attribute.Data.Input); string dialectName = attribute.Context.Domain.Dialect.Parameter(paramName); Parameter param = new Parameter(paramName, attribute.Data.Input); IProjectionAttribute result = attribute.Append(dialectName).Append(param); if (attribute.Metadata.HasFlag(ProjectionMetadataFlags.Output)) { if (attribute.Context.Domain.Dialect.Support.HasFlag(DialectSupport.OutputParameters)) { ParameterBinding binding = new ParameterBinding(attribute.Data.Output, param.Name); result = result.Append(binding); } if (attribute.Metadata.HasAnyFlag(ProjectionMetadataFlags.Cascade)) { CascadeBinding binding = new CascadeBinding(attribute.Data.Output, attribute.Data.Input); result = result.Append(binding); } } return(result); } else { string paramName = attribute.Context.Lookup.Parameter(attribute.Identity, attribute.Metadata.Identity); string dialectName = attribute.Context.Domain.Dialect.Parameter(paramName); return(attribute.Append(dialectName)); } }
/// <summary> /// Appends the current variable name, e.g. <c>@V0</c>, to the attribute buffer. /// </summary> /// <param name="attribute">The current attribute.</param> /// <returns>A new attribute containing the appended buffer.</returns> public static IProjectionAttribute Var(this IProjectionAttribute attribute) { if (attribute.Data == null) { throw ProjectionException.ValueNotFound(attribute.Metadata); } string variableName = attribute.Context.Lookup.Variable(attribute.Identity, attribute.Data.Input); string dialectName = attribute.Context.Domain.Dialect.Variable(variableName); return(attribute.Append(dialectName)); }
/// <summary> /// Appends the current value in safe literal form, e.g. <c>1</c>, to the attribute buffer. Parameters are used for unsafe literals. /// </summary> /// <param name="attribute">The current attribute.</param> /// <returns>A new attribute containing the appended buffer.</returns> public static IProjectionAttribute Lit(this IProjectionAttribute attribute) { string literal = attribute.Context.Domain.Dialect.Literal(attribute.Data?.Source.Snapshot); if (literal == null) { return(attribute.Par()); } else { return(attribute.Append(literal)); } }
/// <summary> /// Appends the current correlated table name, e.g. <c>"MyTable" T0</c>, to the attribute buffer. /// </summary> /// <param name="attribute">The current attribute.</param> /// <param name="tblAlias">An alternative alias to use for the current table.</param> /// <returns>A new attribute containing the appended buffer.</returns> public static IProjectionAttribute Tbl(this IProjectionAttribute attribute, string tblAlias = null) { attribute = attribute.TblName().Append(" "); if (tblAlias != null) { return(attribute.Append(attribute.Context.Domain.Dialect.Identifier(tblAlias))); } else { return(attribute.Ali()); } }
/// <summary> /// Appends a call to <c>JSON_VALUE</c> from the current column and JSON path, e.g. <c>JSON_VALUE(T0."MyJson", '$.my.value')</c>, to the attribute buffer. /// </summary> /// <param name="attribute">The current attribute.</param> /// <returns>A new attribute containing the appended buffer.</returns> public static IProjectionAttribute Json(this IProjectionAttribute attribute) { IJsonMetadata json = ProjectionHelper.GetJsonMetadata(attribute); IProjectionMetadata metadata = attribute.Metadata; IProjectionMetadata rootMetadata = json.MemberOf.Identity.GetMetadata <IProjectionMetadata>(); attribute = attribute.Append("JSON_VALUE("); try { attribute = attribute.With(metadata: rootMetadata).Col(); } catch (ProjectionException ex) { throw ProjectionException.FromProjection(attribute, "JSON value requires a column to read from.", innerException: ex); } attribute = attribute.Append(","); attribute = attribute.With(metadata: metadata).JsonPath(); attribute = attribute.Append(")"); return(attribute); }
/// <summary> /// Appends the current JSON path literal, e.g. <c>'$.my.value'</c>, to the attribute buffer. /// </summary> /// <param name="attribute">The current attribute.</param> /// <returns>A new attribute containing the appended buffer.</returns> public static IProjectionAttribute JsonPath(this IProjectionAttribute attribute) { IJsonMetadata metadata = attribute.Metadata.Identity.GetMetadata <IJsonMetadata>(); if (metadata == null) { throw ProjectionException.FromProjection(attribute, "JSON metadata not found."); } string literal = attribute.Context.Domain.Dialect.String(metadata.Path); return(attribute.Append(literal)); }
/// <summary> /// Appends the current value in safe literal form, e.g. <c>1</c>, to the attribute buffer. Parameters are used for unsafe literals. /// </summary> /// <param name="attribute">The current attribute.</param> /// <returns>A new attribute containing the appended buffer.</returns> public static IProjectionAttribute Lit(this IProjectionAttribute attribute) { IField field = ProjectionHelper.GetFieldValue(attribute); string literal = attribute.Context.Domain.Dialect.Literal(field?.Value); if (literal == null) { return(attribute.Par()); } else { return(attribute.Append(literal)); } }
/// <summary> /// Appends the <c> AS </c> operator to the current attribute buffer. /// </summary> /// <param name="attribute">The current attribute.</param> /// <returns>A new attribute containing the appended buffer.</returns> public static IProjectionAttribute As(this IProjectionAttribute attribute) => attribute.Append(" AS ");
/// <summary> /// Appends the <c> = </c> operator to the current attribute buffer. /// </summary> /// <param name="attribute">The current attribute.</param> /// <returns>A new attribute containing the appended buffer.</returns> public static IProjectionAttribute Eq(this IProjectionAttribute attribute) => attribute.Append(" = ");
/// <summary> /// Appends the <c>IS NOT NULL</c> operator to the current attribute buffer. /// </summary> /// <param name="attribute">The current attribute.</param> /// <returns>A new attribute containing the appended buffer.</returns> public static IProjectionAttribute IsNotNull(this IProjectionAttribute attribute) => attribute.Append(" IS NOT NULL");