public static string Select(this ISqlDialect d, string table, string schema, List <string> keys) { return(StringBuilderPool.Scoped(sb => { sb.Append("SELECT * FROM ").AppendTable(d, table, schema).AppendWhereClause(d, keys); })); }
public static string Prefix(this Models.Schema schema, string ns = null) { return(StringBuilderPool.Scoped(sb => { sb.Append(ns ?? schema?.Namespace ?? Constants.Schema.DefaultNamespace); })); }
public static string Select(this ISqlDialect d, IDataDescriptor descriptor, string table, string schema, List <string> columns, List <string> keys, List <string> parameters) { return(StringBuilderPool.Scoped(sb => { if (descriptor != null && !d.BeforeSelect(descriptor, sb)) { return; } sb.Append("SELECT "); if (!d.BeforeSelectColumns(descriptor, sb, columns)) { return; } for (var i = 0; i < columns.Count; i++) { sb.AppendName(d, columns[i]); if (i < columns.Count - 1) { sb.Append(", "); } } sb.Append(" FROM ").AppendTable(d, table, schema); sb.AppendWhereClause(descriptor, d, keys, parameters); })); }
public static string Identifier(this string value) { if (string.IsNullOrWhiteSpace(value)) { return("_"); } if (SyntaxFacts.IsValidIdentifier(value)) { return(value); } return(StringBuilderPool.Scoped(sb => { if (IsCSharpKeyword(value)) { sb.Append("@"); } foreach (var c in value) { if (SyntaxFacts.IsIdentifierPartCharacter(c)) { sb.Append(c); } } sb.Append(value); })); }
public static string VersionString(this Models.Schema schema) { return(StringBuilderPool.Scoped(sb => { sb.Append(schema?.Namespace ?? Constants.Schema.DefaultNamespace); })); }
public static string Query(this ISqlDialect d, string table, string schema, IList <string> columns, IList <Filter> filters, IList <Projection> projections, IList <Tuple <string, string, bool> > orderByColumns) { return(StringBuilderPool.Scoped(sb => { AppendQuery(sb, d, table, schema, columns, filters, projections, orderByColumns); })); }
public static string Query <T>(this ISqlDialect d, string table, string schema, IList <string> columns, IList <Filter> filters, IList <Projection> projections, Expression <Func <T, object> >[] orderByColumns) { return(StringBuilderPool.Scoped(sb => { AppendQuery(sb, d, table, schema, columns, filters, projections, orderByColumns); })); }
public static string Delete(this ISqlDialect d, string table, string schema) { return(StringBuilderPool.Scoped(sb => { sb.Append("DELETE FROM "); sb.AppendTable(d, table, schema); })); }
public static string OrderBy <T>(this ISqlDialect dialect, string sql, params Expression <Func <T, object> >[] orderBy) { return(StringBuilderPool.Scoped(sb => { sb.Append(sql); AppendOrderBy(sb, dialect, orderBy); })); }
public static string Delete(this ISqlDialect d, string table, string schema, List <PropertyToColumn> keys) { return(StringBuilderPool.Scoped(sb => { sb.Append("DELETE FROM "); sb.AppendTable(d, table, schema); sb.AppendWhereClause(d, keys.Select(x => x.ColumnName).ToList()); })); }
public static string Delete(this ISqlDialect d, string table, string schema, List <string> keys, List <string> parameters) { return(StringBuilderPool.Scoped(sb => { sb.Append("DELETE FROM "); sb.AppendTable(d, table, schema); sb.AppendWhereClause(d, keys, parameters); })); }
public static string ToBase36(this ulong input) { return(StringBuilderPool.Scoped(sb => { while (input != 0) { sb.Append(Chars[input % Base]); input /= Base; } })); }
public static string Select <T>(ISqlDialect dialect, FieldOptions fields, ProjectionOptions projections) { return(StringBuilderPool.Scoped(sb => { // SELECT * FROM ... sb.Append($"SELECT {BuildFields<T>(dialect, fields, projections)} " + $"FROM {dialect.StartIdentifier}{typeof(T).Name}{dialect.EndIdentifier} r "); if (projections?.Fields == null) { return; } // INNER JOIN... var joins = 0; foreach (var projection in projections.Fields) { var name = projection.Field.ToTitleCase(); if (name.EndsWith("s")) { name = name.Substring(0, name.Length - 1); } switch (projection.Type) { case ProjectionType.OneToOne: /* * INNER JOIN Role r0 ON r0.Id = x0.RoleId */ sb.Append($"INNER JOIN {name} r{joins} ON r{joins}.Id = x{joins}.{name}Id "); break; case ProjectionType.OneToMany: /* * INNER JOIN UserRole x0 ON x0.UserId = r.Id * INNER JOIN Role r0 ON r0.Id = x0.RoleId */ sb.Append( $"INNER JOIN {typeof(T).Name}{name} x{joins} ON x{joins}.{typeof(T).Name}Id = r.Id "); sb.Append($"INNER JOIN {name} r{joins} ON r{joins}.Id = x{joins}.{name}Id "); break; case ProjectionType.Scalar: break; default: throw new ArgumentOutOfRangeException(); } joins++; } })); }
public static string Delete(this ISqlDialect d, IDataDescriptor descriptor, string table, string schema) { return(StringBuilderPool.Scoped(sb => { if (!d.BeforeDelete(descriptor, sb)) { return; } sb.Append("DELETE FROM "); sb.AppendTable(d, table, schema); })); }
public static string Prefix(this Models.Schema schema, string ns = null) { return(StringBuilderPool.Scoped(sb => { sb.Append(ns ?? schema?.Self?.Namespace ?? Constants.Schema.DefaultNamespace); var version = schema?.Self?.Version ?? 0; if (version == 0) { return; } sb.Append($".V{version}"); })); }
public static string Count <T>(this ISqlDialect dialect, FilterOptions filter = null) { return(StringBuilderPool.Scoped(sb => { // SELECT COUNT(1) FROM ... sb.Append($"SELECT COUNT(1) FROM {dialect.StartIdentifier}{typeof(T).Name}{dialect.EndIdentifier}"); // WHERE ... if (filter?.Fields.Count > 0) { sb.Append($" {dialect.Where(filter)}"); } })); }
public string Build() { return(StringBuilderPool.Scoped(sb => { foreach (var item in _context.RouteData.DataTokens) { sb.Append(item.Key) .Append(":") .Append(item.Value); } sb.Append(":"); sb.Append(_context.HttpContext.Request.QueryString); })); }
private static string DefaultFormatter(object[] args) { return(StringBuilderPool.Scoped(sb => { var logLevelString = GetLogLevelShorthand(args); var categoryName = args[1]; var eventId = args[2]; var message = args[3]; sb.Append(logLevelString).Append(':') .Append(categoryName).Append('[').Append(eventId).AppendLine("]") .Append('\t').Append(message); })); }
public static string FullTypeString(this Models.Schema schema, string ns = null) { return(StringBuilderPool.Scoped(sb => { sb.Append(ns ?? schema?.Self?.Namespace ?? Constants.Schema.DefaultNamespace); if (schema?.Self?.Version != 0) { var version = schema?.Self?.Version ?? 0; if (version != 0) { sb.Append(".V").Append(version); } } sb.Append('.').Append(schema.TypeString()); })); }
internal static string DeleteFrom(this ISqlDialect d, string table, string schema, IList <PropertyToColumn> keys) { return(StringBuilderPool.Scoped(sb => { sb.Append("DELETE FROM "); sb.AppendTable(d, table, schema); if (keys != null) { for (var i = 0; i < keys.Count; i++) { sb.Append(i == 0 ? " WHERE " : " AND "); var key = keys[i]; sb.AppendName(d, key.ColumnName).Append(" = ").AppendParameter(d, key.ColumnName); } } })); }
private static Query Select <T>(IDataDescriptor descriptor, List <string> columnFilter, dynamic where, int page, int perPage, params Expression <Func <T, object> >[] orderBy) { QueryAndParameters qp = BuildSelectQueryAndParameters(descriptor, columnFilter, where); if (orderBy?.Length > 0) { qp.sql = Dialect.OrderBy(qp.sql, orderBy); } var pageSql = StringBuilderPool.Scoped(sb => { Dialect.Page(qp.sql, sb); }); qp.parameters.Add($"{Dialect.Parameter}Page", page); qp.parameters.Add($"{Dialect.Parameter}PerPage", perPage); return(new Query(pageSql, qp.parameters)); }
public static string VersionString(this Models.Schema schema) { return(StringBuilderPool.Scoped(sb => { sb.Append(schema?.Self?.Namespace ?? Constants.Schema.DefaultNamespace); if (schema?.Self?.Version == 0) { return; } var version = schema?.Self?.Version ?? 0; if (version == 0) { return; } sb.Append($".V{version}"); })); }
public static string Select(this ISqlDialect d, string table, string schema, List <string> columns, List <string> keys) { return(StringBuilderPool.Scoped(sb => { sb.Append("SELECT "); for (var i = 0; i < columns.Count; i++) { sb.AppendName(d, columns[i]); if (i < columns.Count - 1) { sb.Append(", "); } } sb.Append(" FROM ").AppendTable(d, table, schema).AppendWhereClause(d, keys); })); }
public static string Update(this ISqlDialect d, IDataDescriptor descriptor, string table, string schema, List <string> columns, List <string> keys, List <string> setParameters, List <string> whereParameters, string setSuffix = SetSuffix) { Debug.Assert(columns != null); Debug.Assert(columns.Count == setParameters?.Count && columns.Count >= whereParameters?.Count); return(StringBuilderPool.Scoped(sb => { if (!d.BeforeUpdate(descriptor, sb)) { return; } sb.Append("UPDATE "); sb.AppendTable(d, table, schema).Append(" SET "); if (!d.BeforeUpdateColumns(descriptor, sb, columns)) { return; } for (var i = 0; i < columns.Count; i++) { var column = columns[i]; sb.AppendName(d, column).Append(" = "); sb.AppendParameter(d, setParameters[i] + setSuffix); if (i < columns.Count - 1) { sb.Append(", "); } } if (!d.BeforeWhere(descriptor, sb, keys, whereParameters)) { return; } sb.AppendWhereClause(d, keys, whereParameters); d.AfterWhere(descriptor, sb, keys); })); }
public string Transform(string input) { return(StringBuilderPool.Scoped(sb => { if (input == null) { return; } sb.Append(input); if (string.IsNullOrWhiteSpace(input) || char.IsLower(input[0])) { return; } sb[0] = char.ToLowerInvariant(sb[0]); })); }
public override string ToString() { var output = StringBuilderPool.Scoped(sb => { if (Sort.HasValue) { switch (Sort) { case StringSort.Ascending: foreach (var line in _bucket.OrderBy(s => s)) { sb.AppendLine(line); } break; case StringSort.Descending: foreach (var line in _bucket.OrderByDescending(s => s)) { sb.AppendLine(line); } break; case null: break; default: throw new ArgumentOutOfRangeException(); } } else { foreach (var line in _bucket) { sb.AppendLine(line); } } }); _buffer.Append(output); return(output); }
public static string Update(this ISqlDialect d, IDataDescriptor descriptor, string table, string schema, List <PropertyToColumn> columns, List <string> keys, string setSuffix = SetSuffix) { return(StringBuilderPool.Scoped(sb => { if (!d.BeforeUpdate(descriptor, sb)) { return; } sb.Append("UPDATE "); sb.AppendTable(d, table, schema).Append(" SET "); if (!d.BeforeUpdateColumns(descriptor, sb, columns.Select(x => x.ColumnName).ToList())) { return; } for (var i = 0; i < columns.Count; i++) { var column = columns[i]; sb.AppendName(d, column.ColumnName).Append(" = ") .AppendParameter(d, column.ColumnName) .Append(setSuffix); if (i < columns.Count - 1) { sb.Append(", "); } } if (!d.BeforeWhere(descriptor, sb, keys)) { return; } sb.AppendWhereClause(d, keys); d.AfterWhere(descriptor, sb, keys); })); }
public static string Delete(this ISqlDialect d, IDataDescriptor descriptor, string table, string schema, List <string> keys, List <string> parameters) { return(StringBuilderPool.Scoped(sb => { if (!d.BeforeDelete(descriptor, sb)) { return; } sb.Append("DELETE FROM "); sb.AppendTable(d, table, schema); if (!d.BeforeWhere(descriptor, sb, keys, parameters)) { return; } sb.AppendWhereClause(descriptor, d, keys, parameters); })); }
public static string Update(this ISqlDialect d, string table, string schema, List <string> columns, List <string> keys, string setSuffix = SetSuffix) { return(StringBuilderPool.Scoped(sb => { sb.Append("UPDATE "); sb.AppendTable(d, table, schema).Append(" SET "); for (var i = 0; i < columns.Count; i++) { var column = columns[i]; sb.AppendName(d, column).Append(" = ").AppendParameter(d, column).Append(setSuffix); if (i < columns.Count - 1) { sb.Append(", "); } } sb.AppendWhereClause(d, keys); })); }
public static string Build <T>(this ISqlDialect dialect, SortOptions sort = null, FieldOptions fields = null, FilterOptions filter = null, ProjectionOptions projections = null) { return(StringBuilderPool.Scoped(sb => { // SELECT * FROM ... sb.Append(ProjectionBuilder.Select <T>(dialect, fields, projections)); // WHERE ... if (filter?.Fields.Count > 0) { sb.Append($" {dialect.Where(filter)}"); } // ORDER BY ... if (sort?.Fields.Count > 0) { sb.Append($" {SortingBuilder.OrderBy(dialect, sort)}"); } })); }