public void TestTableColumnsSQL() { _context.Input = @"CREATE PROCEDURE sp{TABLE.NAME}_Insert( {TABLE.COLUMNS NOPRIMARY} @{COLUMN.NAME} {COLUMN.TYPE}, {/TABLE.COLUMNS}{TABLE.COLUMNS PRIMARY}@{COLUMN.NAME} {COLUMN.TYPE} OUTPUT{/TABLE.COLUMNS} ) AS INSERT INTO {TABLE.NAME} ({TABLE.COLUMNS}{COLUMN.NAME}{IF NOT LAST},{/IF} {/TABLE.COLUMNS}) VALUES({TABLE.COLUMNS}@{COLUMN.NAME}{IF NOT LAST},{/IF} {/TABLE.COLUMNS}) {TABLE.COLUMNS PRIMARY} SET @{COLUMN.NAME} = @{COLUMN.NAME} {/TABLE.COLUMNS} "; ColumnsExpression columns = new ColumnsExpression(); columns.AddExpression(new ColumnNameExpression()); columns.AddExpression(new ColumnTypeExpression()); columns.AddExpression(new ColumnLengthExpression()); columns.AddExpression(new ColumnIfExpression()); _parser.AddExpression(columns); _parser.AddExpression(new TableNameExpression()); _parser.Interpret(_context); }
public void ConstructExpressionWithSelector() { var expression = ColumnsExpression.Create <Person, object>((p) => new { p.Id, p.FirstName, p.LastName }, GetTableInfo()); expression.ColumnsPart.Should().Be("Id, Name, LastName"); }
public void TestTableColumnsClass() { _context.Input = @"public class {TABLE.NAME}{ {TABLE.COLUMNS} private {MAP COLUMN.TYPE} _{COLUMN.NAME}; //{COLUMN.LENGHT} {TABLE.NULLABLE} {/TABLE.COLUMNS} public void {TABLE.NAME}(){ } {TABLE.COLUMNS} //{TABLE.NAME} public {MAP COLUMN.TYPE} {COLUMN.NAME} { set{ _{COLUMN.NAME} = value; } get{ return _{COLUMN.NAME}; } } {/TABLE.COLUMNS} } "; ColumnsExpression columns = new ColumnsExpression(); columns.AddExpression(new ColumnNameExpression()); columns.AddExpression(new ColumnTypeExpression()); columns.AddExpression(new ColumnMapTypeExpression()); //columns.AddExpression(new LiteralExpression("[A-Z. ]+","")); _parser.AddExpression(columns); _parser.AddExpression(new TableNameExpression()); _parser.Interpret(_context); }
/// <summary> /// Add select part to sql. /// </summary> /// <typeparam name="TResult"></typeparam> /// <param name="selector">The selector.</param> /// <returns> /// Query for enumerable models. /// </returns> /// <exception cref="ArgumentNullException">if <c>sqlPart</c> is null or white string.</exception> /// <remarks> /// When <c>Select</c> method is not call, query take columns by T model. /// </remarks> public IQuery <T> Select <TResult>(Func <T, TResult> selector) { Check.NotNull(selector, nameof(selector)); this.SelectExpression.SetColumnsExpression(ColumnsExpression.Create(selector, _databaseMapper.GetTableInfo <T>())); return(this); }
public void TestIfNullable() { _context.Input = @"{TABLE.COLUMNS}{IF COLUMN.NULLABLE}{COLUMN.NAME}=NULL{/IF}{IF NOT COLUMN.NULLABLE}FALSE{/IF} {/TABLE.COLUMNS}"; ColumnsExpression columns = new ColumnsExpression(); columns.AddExpression(new ColumnNameExpression()); columns.AddExpression(new ColumnIfNullableExpression()); _parser.AddExpression(columns); _parser.Interpret(_context); }
public void TestColumnsNoPrimary() { _context.Input = @"{TABLE.COLUMNS NOPRIMARY}{COLUMN.NAME} {/TABLE.COLUMNS}"; ColumnsExpression columns = new ColumnsExpression(); columns.AddExpression(new ColumnNameExpression()); _parser.AddExpression(columns); _parser.Interpret(_context); }
public void SetColumnsExpression() { var tableInfo = new DatabaseMapper(new ConventionModelMapper()).GetTableInfo <Person>(); var selectExpression = new SelectExpression(tableInfo); var expression = new ColumnsExpression("Id"); selectExpression.SetColumnsExpression(expression); selectExpression.ColumnsExpression.Should().Be(expression); }
public void TestColumnsIfLast() { _context.Input = @"{TABLE.COLUMNS} {IF NOT LAST}NOT LAST{/IF} {IF LAST} LAST{/IF} {/TABLE.COLUMNS}"; ColumnsExpression columns = new ColumnsExpression(); columns.AddExpression(new ColumnIfExpression()); _parser.AddExpression(columns); _parser.Interpret(_context); }
public void TestIfType() { _context.Input = @" {TABLE.COLUMNS} {IF COLUMN.TYPE EQ 'int|numeric()'}int _{COLUMN.NAME}{/IF} {IF COLUMN.TYPE NE 'int'}string _{COLUMN.NAME}{/IF} {/TABLE.COLUMNS}"; ColumnsExpression colsExpression = new ColumnsExpression(); colsExpression.AddExpression(new ColumnIfTypeExpression()); colsExpression.AddExpression(new ColumnNameExpression()); _parser.AddExpression(colsExpression); _parser.Interpret(_context); }
public void TestColumnNameMatchesExpression() { _context.Input = @"{TABLE.COLUMNS}" + @"{IF COLUMN.NAME =~ 'Id$'}{COLUMN.NAME} ES ID{/IF}" + "\n" + @"{IF COLUMN.NAME !~ 'Id$'}{COLUMN.NAME}{/IF}" + "\n" + "{/TABLE.COLUMNS}"; ColumnsExpression columns = new ColumnsExpression(); columns.AddExpression(new ColumnNameExpression()); columns.AddExpression(new ColumnNameMatchesExpression()); _parser.AddExpression(columns); _parser.Interpret(_context); }
public void TestColumnNaming() { _context.Input = @"{TABLE.COLUMNS}" + @"Normal: {COLUMN.NAME}" + "\n" + // @"Camel: {COLUMN.NAME CAMEL}" + "\n" + // @"Pascal: {COLUMN.NAME PASCAL}" + "\n" + // @"Upper: {COLUMN.NAME UPPER}" + "\n" + // @"Lower: {COLUMN.NAME LOWER}" + "\n" + @"Underscore: {COLUMN.NAME UNDERSCORE}" + "\n" + @"Human: {COLUMN.NAME HUMAN}" + "\n" + @"{/TABLE.COLUMNS}"; ColumnsExpression columns = new ColumnsExpression(); columns.AddExpression(new ColumnNameExpression()); _parser.AddExpression(columns); _parser.Interpret(_context); // Console.WriteLine(_context.Output); }
/// <summary> /// Visits the columns. /// </summary> /// <param name="columnExpression">The column expression.</param> /// <returns> /// Expression /// </returns> public virtual Expression VisitColumns(ColumnsExpression columnExpression) { _sqlBuilder.Append(columnExpression.ColumnsPart); return(columnExpression); }
/// <summary> /// Visits the columns. /// </summary> /// <param name="columnExpression">The column expression.</param> /// <returns> /// Expression /// </returns> public virtual Expression VisitColumns(ColumnsExpression columnExpression) { SqlBuilder.Append(columnExpression.ColumnsPart); _columnsPosition = SqlBuilder.Length; return(columnExpression); }
public void ConstructExpressionWithColumnsList() { var expression = new ColumnsExpression("Id", "FirstName", "LastName"); expression.ColumnsPart.Should().Be("Id, FirstName, LastName"); }
public void ConstructExpressionWithoutSelectKeyWord() { var expression = new ColumnsExpression("Select Id, FirstName, LastName"); expression.ColumnsPart.Should().Be("Id, FirstName, LastName"); }