Search in sources :

Example 6 with JdbcSqlQuery

use of com.github.mgramin.sqlboot.sql.impl.JdbcSqlQuery in project sql-boot by sql-boot.

the class SqlResourceTypeTest method read.

@Test
public void read() throws Exception {
    final String sql = "select * from (select table_schema as \"@table_schema\", table_name as \"@table_name\" " + "from information_schema.tables)";
    final ResourceType type = new WhereWrapper(new SqlResourceType(new JdbcSqlQuery(dataSource, new GroovyTemplateGenerator(sql)), asList("table")));
    assertEquals(3, type.read(new DbUri("table/m.column")).count());
}
Also used : DbUri(com.github.mgramin.sqlboot.model.uri.impl.DbUri) JdbcSqlQuery(com.github.mgramin.sqlboot.sql.impl.JdbcSqlQuery) ResourceType(com.github.mgramin.sqlboot.model.resource_type.ResourceType) GroovyTemplateGenerator(com.github.mgramin.sqlboot.template.generator.impl.GroovyTemplateGenerator) WhereWrapper(com.github.mgramin.sqlboot.model.resource_type.wrappers.list.WhereWrapper) Test(org.junit.Test)

Example 7 with JdbcSqlQuery

use of com.github.mgramin.sqlboot.sql.impl.JdbcSqlQuery in project sql-boot by sql-boot.

the class SqlResourceTypeTest method path.

@Test
public void path() {
    final String sql = "select _schema, _table, _column from (select table_schema as \"_schema\", table_name as \"_table\", column_name as \"_column\"" + "from information_schema.columns)";
    final ResourceType type = new SqlResourceType(new JdbcSqlQuery(dataSource, new GroovyTemplateGenerator(sql)), asList("column"));
    final List<String> path = type.path();
    assertEquals("schema", path.get(0));
    assertEquals("table", path.get(1));
    assertEquals("column", path.get(2));
}
Also used : JdbcSqlQuery(com.github.mgramin.sqlboot.sql.impl.JdbcSqlQuery) ResourceType(com.github.mgramin.sqlboot.model.resource_type.ResourceType) GroovyTemplateGenerator(com.github.mgramin.sqlboot.template.generator.impl.GroovyTemplateGenerator) Test(org.junit.Test)

Aggregations

JdbcSqlQuery (com.github.mgramin.sqlboot.sql.impl.JdbcSqlQuery)7 Test (org.junit.Test)5 ResourceType (com.github.mgramin.sqlboot.model.resource_type.ResourceType)4 GroovyTemplateGenerator (com.github.mgramin.sqlboot.template.generator.impl.GroovyTemplateGenerator)4 WhereWrapper (com.github.mgramin.sqlboot.model.resource_type.wrappers.list.WhereWrapper)2 DbUri (com.github.mgramin.sqlboot.model.uri.impl.DbUri)2 DbResourceBodyWrapper (com.github.mgramin.sqlboot.model.resource.wrappers.DbResourceBodyWrapper)1 MarkdownFile (com.github.mgramin.sqlboot.model.resource_type.impl.composite.md.MarkdownFile)1 SchemaJdbcResourceType (com.github.mgramin.sqlboot.model.resource_type.impl.jdbc.schema.SchemaJdbcResourceType)1 FunctionJdbcResourceType (com.github.mgramin.sqlboot.model.resource_type.impl.jdbc.schema.function.FunctionJdbcResourceType)1 ProcedureJdbcResourceType (com.github.mgramin.sqlboot.model.resource_type.impl.jdbc.schema.procedure.ProcedureJdbcResourceType)1 TableJdbcResourceType (com.github.mgramin.sqlboot.model.resource_type.impl.jdbc.schema.table.TableJdbcResourceType)1 ColumnJdbcResourceType (com.github.mgramin.sqlboot.model.resource_type.impl.jdbc.schema.table.column.ColumnJdbcResourceType)1 FkJdbcResourceType (com.github.mgramin.sqlboot.model.resource_type.impl.jdbc.schema.table.fk.FkJdbcResourceType)1 IndexJdbcResourceType (com.github.mgramin.sqlboot.model.resource_type.impl.jdbc.schema.table.index.IndexJdbcResourceType)1 PkJdbcResourceType (com.github.mgramin.sqlboot.model.resource_type.impl.jdbc.schema.table.pk.PkJdbcResourceType)1 ChildTableJdbcResourceType (com.github.mgramin.sqlboot.model.resource_type.impl.jdbc.schema.table.relation.ChildTableJdbcResourceType)1 ParentTableJdbcResourceType (com.github.mgramin.sqlboot.model.resource_type.impl.jdbc.schema.table.relation.ParentTableJdbcResourceType)1 ViewJdbcResourceType (com.github.mgramin.sqlboot.model.resource_type.impl.jdbc.schema.view.ViewJdbcResourceType)1 SqlResourceType (com.github.mgramin.sqlboot.model.resource_type.impl.sql.SqlResourceType)1