/// <summary> /// Compiles an <see cref="IQueryFragment"/> to a <see cref="QueryResult"/>. /// </summary> /// <param name="query">The <see cref="IQueryFragment"/>.</param> /// <returns>The <see cref="QueryResult"/>.</returns> public virtual QueryResult Compile(IQueryFragment query) { QueryBuilder queryBuilder = new QueryBuilder(this); query.Compile(queryBuilder, this); return(queryBuilder.ToQueryResult()); }
public void Typed_Alias_Setup() { IAlias <Person> person = sql.Alias <Person>(); query = sql.Query .Select(person.All) .From(person) .Where(person["Id"].Eq(1)); }
public void Typed_Alias_Expression_Setup() { IAlias <Person> person = sql.Alias <Person>(); query = sql.Query .Select(person.All) .From(person) .Where(person[x => x.Id].Eq(1)); }
/// <summary> /// Creates an "like" operator. /// </summary> /// <param name="left">The <see cref="IQueryFragment"/>.</param> /// <param name="right">Right value.</param> /// <returns>The "like" operator.</returns> public static IOperator Like(this IQueryFragment left, Expression <Func <object> > right) { if (right == null) { return(Like(left, (object)right)); } return(SqlBuilder.Instance.Like(left, SqlBuilder.Instance.Val(right))); }
public void String_Alias_Setup() { IAlias person = sql.Alias("person"); query = sql.Query .Select(person.All) .From(person) .Where(person["Id"].Eq(1)); }
public void Expression_Setup() { int id = 1; Person person = null; query = sql.Query .Select(() => person) .From(() => person) .Where(() => person.Id == id); }
/// <summary> /// Creates or adds an "offset" clause. /// </summary> /// <param name="offset">The number of rows to skip.</param> /// <returns>The raw query.</returns> public virtual IRawQuery Offset(object offset) { if (OffsetValue is IOffset offsetValue) { offsetValue.Offset(offset); } else { OffsetValue = SqlBuilder.Instance.Offset(offset); } return(this); }
/// <summary> /// Creates or adds "fetch" clause. /// </summary> /// <param name="fetch">The number of rows to return.</param> /// <returns>The raw query.</returns> public virtual IRawQuery Fetch(object fetch) { if (OffsetValue is IOffset offsetValue) { offsetValue.Fetch(fetch); } else { OffsetValue = SqlBuilder.Instance.Fetch(fetch); } return(this); }
/// <summary> /// Writes an object to the query. /// </summary> /// <param name="value">The object to write.</param> /// <returns>The query builder.</returns> public QueryBuilder WriteValue(object value) { IQueryFragment queryFragment = value as IQueryFragment; if (queryFragment != null) { WriteFragment(queryFragment); } else { AddParameter(value); } return(this); }
/// <summary> /// Initializes a new instance of the <see cref="QueryOperator"/> class. /// </summary> /// <param name="op">The operator.</param> /// <param name="left">The left value.</param> /// <param name="right">The right value.</param> public QueryOperator(string op, IQueryFragment left, IQueryFragment right) { if (left == null) { throw new ArgumentNullException(nameof(left), "Left value is null."); } if (right == null) { throw new ArgumentNullException(nameof(right), "Right value is null."); } Op = op; Left = left; Right = right; }
/// <summary> /// Writes a <see cref="IQueryFragment"/> to the builder. /// </summary> /// <param name="value">The <see cref="IQueryFragment"/> to write.</param> /// <param name="addParentheses">If add parentheses to the <see cref="IQueryFragment"/>.</param> /// <returns>The string builder.</returns> public ToStringBuilder WriteFragment(IQueryFragment value, bool addParentheses) { if (addParentheses) { Builder.Append("("); } Builder.Append(value.ToString()); if (addParentheses) { Builder.Append(")"); } return(this); }
/// <summary> /// Writes a <see cref="IQueryFragment"/> to the query. /// </summary> /// <param name="value">The <see cref="IQueryFragment"/> to write.</param> /// <param name="addParentheses">If add parentheses to the <see cref="IQueryFragment"/>.</param> /// <returns>The query builder.</returns> public QueryBuilder WriteFragment(IQueryFragment value, bool addParentheses) { if (addParentheses) { Builder.Append("("); } value.Compile(this, Engine); if (addParentheses) { Builder.Append(")"); } return(this); }
/// <summary> /// Sets a value to write after the query. /// </summary> /// <param name="value">The value to write after the query.</param> /// <returns>The raw query.</returns> public virtual IRawQuery After(IQueryFragment value) { AfterValue = value; return(this); }
/// <summary> /// Sets a value to write before the query. /// </summary> /// <param name="value">The value to write before the query.</param> /// <returns>The raw query.</returns> public virtual IRawQuery Before(IQueryFragment value) { BeforeValue = value; return(this); }
/// <summary> /// Creates an "union all" operator. /// </summary> /// <param name="left">Left value.</param> /// <param name="right">Right value.</param> /// <returns>The "union all" operator.</returns> public virtual IOperator UnionAll(IQueryFragment left, IQueryFragment right) { return(new QueryOperator("UNION ALL", left, right)); }
/// <summary> /// Creates an "offset fetch" clause. /// </summary> /// <param name="offset">The number of rows to skip.</param> /// <param name="fetch">The number of rows to return.</param> /// <returns>The raw query.</returns> public virtual IRawQuery Offset(object offset, object fetch) { OffsetValue = SqlBuilder.Instance.Offset(offset, fetch); return(this); }
/// <summary> /// Creates an "except" operator. /// </summary> /// <param name="left">Left value.</param> /// <param name="right">Right value.</param> /// <returns>The "except" operator.</returns> public virtual IOperator Except(IQueryFragment left, IQueryFragment right) { return(new QueryOperator("EXCEPT", left, right)); }
/// <summary> /// Sets the query of the CTE. /// </summary> /// <param name="query">The query.</param> /// <returns>The CTE.</returns> public virtual ICte As(IRawQuery query) { Query = query; return(this); }
/// <summary> /// Creates a "join" clause with a subquery. /// </summary> /// <param name="value">The subquery.</param> /// <param name="alias">The alias.</param> /// <param name="joinType">The type of join, by default inner join.</param> /// <typeparam name="T">The type of the table.</typeparam> /// <returns>The "join" clause.</returns> public virtual IJoin Join <T>(IQueryFragment value, Expression <Func <T> > alias, JoinType joinType = JoinType.Inner) { return(new JoinFrom(joinType).Join(value, alias)); }
/// <summary> /// Adds a raw "top" clause. /// <para>You must write the entire clause.</para> /// </summary> /// <param name="top">The "top" clause.</param> /// <returns>The "update" statement.</returns> public virtual IUpdate Top(IRawSql top) { TopValue = top; return(this); }
public void Raw_Format_Setup() { IAlias person = sql.Alias("person"); query = sql.RawQuery("SELECT {0} FROM {1} WHERE {2} = {3}", person.All, person, person["Id"], 1); }
/// <summary> /// Creates a "from" clause with a subquery. /// </summary> /// <param name="value">The subquery.</param> /// <param name="aliasName">The alias name.</param> /// <returns>The "from" clause.</returns> public virtual IFrom From(IQueryFragment value, string aliasName) { return(new From(value, aliasName)); }
/// <summary> /// Creates a "from" clause with a subquery. /// </summary> /// <param name="value">The subquery.</param> /// <param name="alias">The alias.</param> /// <returns>The "from" clause.</returns> public virtual IFrom From(IQueryFragment value, IAlias alias) { return(new From(value, alias)); }
/// <summary> /// Creates a "from" clause with a subquery. /// </summary> /// <param name="value">The subquery.</param> /// <param name="alias">The alias.</param> /// <typeparam name="T">The type of the table.</typeparam> /// <returns>The "from" clause.</returns> public virtual IFrom From <T>(IQueryFragment value, Expression <Func <T> > alias) { return(new From(value, Alias <T>(alias))); }
/// <summary> /// Creates a "join" clause with a subquery. /// </summary> /// <param name="value">The subquery.</param> /// <param name="aliasName">The alias name.</param> /// <param name="joinType">The type of join, by default inner join.</param> /// <returns>The "join" clause.</returns> public virtual IJoin Join(IQueryFragment value, string aliasName, JoinType joinType = JoinType.Inner) { return(new JoinFrom(joinType).Join(value, aliasName)); }
/// <summary> /// Sets a raw "offset" clause. /// <para>You must write the entire clause.</para> /// </summary> /// <param name="offset">The "offset" clause.</param> /// <returns>The raw query.</returns> public virtual IRawQuery Offset(IRawSql offset) { OffsetValue = offset; return(this); }
/// <summary> /// Writes a <see cref="IQueryFragment"/> to the query. /// </summary> /// <param name="value">The <see cref="IQueryFragment"/> to write.</param> /// <returns>The query builder.</returns> public QueryBuilder WriteFragment(IQueryFragment value) { return(WriteFragment(value, value is ISubQuery)); }
/// <summary> /// Creates an "intersect" operator. /// </summary> /// <param name="left">Left value.</param> /// <param name="right">Right value.</param> /// <returns>The "intersect" operator.</returns> public virtual IOperator Intersect(IQueryFragment left, IQueryFragment right) { return(new QueryOperator("INTERSECT", left, right)); }
/// <summary> /// Creates an "like" operator. /// </summary> /// <param name="left">The <see cref="IQueryFragment"/>.</param> /// <param name="right">Right value.</param> /// <returns>The "like" operator.</returns> public static IOperator Like(this IQueryFragment left, object right) { return(SqlBuilder.Instance.Like(left, right)); }
/// <summary> /// Creates a "join" clause with a subquery. /// </summary> /// <param name="value">The subquery.</param> /// <param name="alias">The alias.</param> /// <param name="joinType">The type of join, by default inner join.</param> /// <returns>The "join" clause.</returns> public virtual IJoin Join(IQueryFragment value, IAlias alias, JoinType joinType = JoinType.Inner) { return(new JoinFrom(joinType).Join(value, alias)); }