Search in sources :

Example 21 with ResourceType

use of com.github.mgramin.sqlboot.model.resource_type.ResourceType 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 22 with ResourceType

use of com.github.mgramin.sqlboot.model.resource_type.ResourceType 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

ResourceType (com.github.mgramin.sqlboot.model.resource_type.ResourceType)22 Test (org.junit.Test)18 DbUri (com.github.mgramin.sqlboot.model.uri.impl.DbUri)16 SqlPlaceholdersWrapper (com.github.mgramin.sqlboot.model.uri.wrappers.SqlPlaceholdersWrapper)14 DbResource (com.github.mgramin.sqlboot.model.resource.DbResource)13 JdbcSqlQuery (com.github.mgramin.sqlboot.sql.impl.JdbcSqlQuery)4 GroovyTemplateGenerator (com.github.mgramin.sqlboot.template.generator.impl.GroovyTemplateGenerator)4 FsResourceTypes (com.github.mgramin.sqlboot.model.resource_type.impl.composite.FsResourceTypes)3 Uri (com.github.mgramin.sqlboot.model.uri.Uri)3 ProcedureJdbcResourceType (com.github.mgramin.sqlboot.model.resource_type.impl.jdbc.schema.procedure.ProcedureJdbcResourceType)2 WhereWrapper (com.github.mgramin.sqlboot.model.resource_type.wrappers.list.WhereWrapper)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ResponseEntity (org.springframework.http.ResponseEntity)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 BootException (com.github.mgramin.sqlboot.exceptions.BootException)1 DbConnectionList (com.github.mgramin.sqlboot.model.connection.DbConnectionList)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