public void TestCreateDropIndex(Type runnerType) { var runner = (IQueryRunner)Provider.GetRequiredService(runnerType); ResetDb(runner); var sqlRunner = (SqlQueryRunner)runner; var parser = new SqlSchemaParser(); var index = new Schema.Index() { Name = "IX_TEST", Columns = new List <string>() { nameof(TypeValue.IntValue) }, Unique = true, }; var addIndex = parser.ParseAddIndex(DB.TypeValues, index); sqlRunner.ExecuteNonQuery(new List <SqlStatement>() { addIndex }, new List <KeyValuePair <string, object> >()); var dropIndex = parser.ParseDropIndex(DB.TypeValues, index); sqlRunner.ExecuteNonQuery(new List <SqlStatement>() { dropIndex }, new List <KeyValuePair <string, object> >()); }
static List <SqlTable> ParseMetadata(DatabaseContext context) { var parser = new SqlSchemaParser(); var metadata = new List <SqlTable>(); foreach (var fromQuery in context.FromQueries) { var stmt = parser.ParseCreateTable(fromQuery); var columns = stmt.Columns; var foreignKeys = new List <SqlForeignKey>(); foreach (var foreignKey in fromQuery.ForeignKeys) { var foreignKeyStmt = parser.ParseAddForeignKey(fromQuery, foreignKey); foreignKeys.Add(foreignKeyStmt.ForeignKey); } var indices = new List <SqlIndex>(); foreach (var index in fromQuery.Indices) { var indexStmt = parser.ParseAddIndex(fromQuery, index); indices.Add(indexStmt.Index); } metadata.Add(new SqlTable() { TableName = fromQuery.TableName, Columns = columns, ForeignKeys = foreignKeys, Indices = indices, }); } return(metadata); }