Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into 326
Browse files Browse the repository at this point in the history
  • Loading branch information
mgramin committed May 28, 2019
2 parents 136fa70 + 727b11d commit b44d65b
Show file tree
Hide file tree
Showing 23 changed files with 159 additions and 221 deletions.
3 changes: 3 additions & 0 deletions conf/h2/md/database/instance/locks/locks.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
````sql
/*
{ "name": "locks" }
*/
select "@schema"
, "@table"
, "@session"
Expand Down
3 changes: 3 additions & 0 deletions conf/h2/md/database/instance/query/query.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
````sql
/*
{ "name": "query" }
*/
select "@statement" from (
select SQL_STATEMENT as "@statement"
, EXECUTION_COUNT
Expand Down
3 changes: 3 additions & 0 deletions conf/h2/md/database/instance/sessions/sessions.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
````sql
/*
{ "name": "sessions" }
*/
select "@id" /* { "label": "id", "description": "ID", "visible": true } */
, USER_NAME /* { "label": "user", "description": "User name", "visible": true } */
, session_start /* { "label": "session start", "description": "Session start", "visible": true } */
Expand Down
3 changes: 3 additions & 0 deletions conf/h2/md/database/schema/schema.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
````sql
/*
{ "name": "schema" }
*/
select "@schema" /* { "label": "schema", "description": "Schema", "visible": true } */
, CATALOG_NAME /* { "label": "catalog", "description": "Catalog" } */
, SCHEMA_OWNER /* { "label": "owner", "description": "Schema owner" } */
Expand Down
83 changes: 83 additions & 0 deletions conf/h2/md/database/schema/table.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
````sql
/*
{ "name": "table" }
*/
select "@schema" /* { "label": "owner", "description": "Owner of the table", "visible": true } */
, "@table" /* { "label": "table name", "description": "Name of the table", "visible": true } */
, remarks properties
, last_modification /* { "label": "last modification", "description": "Last modification" } */
, table_type /* { "label": "table type", "description": "Typical types", "visible": true, "values": ['TABLE', 'VIEW', 'SYSTEM TABLE', 'GLOBAL TEMPORARY', 'LOCAL TEMPORARY', 'ALIAS', 'SYNONYM'] } */
from (select t.table_schema as "@schema"
, t.table_name as "@table"
, t.*
from information_schema.tables t
where lower(t.table_schema) like lower('${uri.path(0)}')
and lower(t.table_name) like lower('${uri.path(1)}'))
order by "@schema", "@table"
````

````sql
/*
{ "name": "column" }
*/
select "@schema" /* { "label": "owner", "description": "Owner of the table", "visible": true } */
, "@table" /* { "label": "table name", "description": "Name of the table", "visible": true } */
, "@column" /* { "label": "column name", "description": "Name of the column", "visible": true } */
, type_name /* { "label": "type name", "description": "Data source dependent type name, for a UDT the type name is fully qualified", "visible": true } */
, character_maximum_length /* { "label": "size", "description": "Column size", "visible": true } */
, nullable /* { "label": "nullable", "description": "Is NULL allowed", "visible": true } */
, column_default /* { "label": "default value", "description": "Default value for the column, which should be interpreted as a string when the value is enclosed in single quotes (may be null)" } */
from (select c.table_schema as "@schema"
, c.table_name as "@table"
, c.column_name as "@column"
, c.*
from information_schema.columns c)
````

````sql
/*
{ "name": "pk" }
*/
select "@schema" /* { "label": "owner", "description": "Owner of the table", "visible": true } */
, "@table" /* { "label": "table name", "description": "Name of the table", "visible": true } */
, "@pk" /* { "label": "pk", "description": "Primary key name", "visible": true } */
, COLUMN_LIST
, REMARKS
, CHECK_EXPRESSION
from (select c.table_schema as "@schema"
, c.table_name as "@table"
, c.constraint_name as "@pk"
, c.*
from information_schema.constraints c)
````

````sql
/*
{ "name": "index" }
*/
select "@schema" /* { "label": "owner", "description": "Owner of the table", "visible": true } */
, "@table" /* { "label": "table name", "description": "Name of the table", "visible": true } */
, "@index" /* { "label": "index name", "description": "Name of the index", "visible": true } */
, ORDINAL_POSITION
, COLUMN_NAME
, CARDINALITY
, PRIMARY_KEY
, INDEX_TYPE_NAME
, IS_GENERATED
, INDEX_TYPE
, ASC_OR_DESC
, PAGES
, FILTER_CONDITION
, REMARKS
, SQL
, ID
, SORT_TYPE
, CONSTRAINT_NAME
, INDEX_CLASS
, AFFINITY
from (select TABLE_SCHEMA as "@schema"
, TABLE_NAME as "@table"
, INDEX_NAME as "@index"
, i.*
from information_schema.indexes i)
````
14 changes: 0 additions & 14 deletions conf/h2/md/database/schema/table/column/column.md

This file was deleted.

27 changes: 0 additions & 27 deletions conf/h2/md/database/schema/table/index/index.md

This file was deleted.

13 changes: 0 additions & 13 deletions conf/h2/md/database/schema/table/pk/pk.md

This file was deleted.

14 changes: 0 additions & 14 deletions conf/h2/md/database/schema/table/table.md

This file was deleted.

8 changes: 0 additions & 8 deletions conf/h2/sql/database/instance/locks/locks.sql

This file was deleted.

14 changes: 0 additions & 14 deletions conf/h2/sql/database/instance/query/query.sql

This file was deleted.

13 changes: 0 additions & 13 deletions conf/h2/sql/database/instance/sessions/sessions.sql

This file was deleted.

11 changes: 0 additions & 11 deletions conf/h2/sql/database/schema/schema.sql

This file was deleted.

12 changes: 0 additions & 12 deletions conf/h2/sql/database/schema/table/column/column.sql

This file was deleted.

25 changes: 0 additions & 25 deletions conf/h2/sql/database/schema/table/index/index.sql

This file was deleted.

11 changes: 0 additions & 11 deletions conf/h2/sql/database/schema/table/pk/pk.sql

This file was deleted.

12 changes: 0 additions & 12 deletions conf/h2/sql/database/schema/table/table.sql

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ import com.github.mgramin.sqlboot.model.resourcetype.wrappers.list.SortWrapper
import com.github.mgramin.sqlboot.model.uri.Uri
import com.github.mgramin.sqlboot.template.generator.impl.GroovyTemplateGenerator
import com.github.mgramin.sqlboot.tools.files.file.impl.MarkdownFile
import com.github.mgramin.sqlboot.tools.files.file.impl.SimpleFile
import org.springframework.core.io.FileSystemResource
import reactor.core.publisher.Flux
import java.io.File
import java.nio.charset.Charset
import java.nio.charset.StandardCharsets.UTF_8

/**
Expand Down Expand Up @@ -78,20 +76,20 @@ class FsResourceType(
File(path)
.walkTopDown()
.filter { it.isFile }
.filter { it.extension.equals("md", true) || it.extension.equals("sql", true) }
.map { return@map if (it.extension.equals("md", true)) MarkdownFile(it.name, it.readText(UTF_8)) else SimpleFile(it.name, it.readText(UTF_8).toByteArray()) }
.filter { it.extension.equals("md", true) }
.map { MarkdownFile(it.name, it.readText(UTF_8)) }
.filter { it.content().isNotEmpty() }
.flatMap { it.parse().map { v -> v.value }.asSequence() }
.map { createObjectType(it) }
.toList()

private fun createObjectType(it: com.github.mgramin.sqlboot.tools.files.file.File) =
private fun createObjectType(it: String) =
TypeWrapper(
SelectWrapper(
SortWrapper(
BodyWrapper(
SqlResourceType(
aliases = listOf(File(it.name()).nameWithoutExtension),
sql = it.content().toString(Charset.defaultCharset()),
sql = it,
endpoints = endpoints,
dialects = dialects),
templateGenerator = GroovyTemplateGenerator("[EMPTY BODY]")))))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import reactor.core.publisher.Flux
* Created by MGramin on 12.07.2017.
*/
class SqlResourceType(
private val aliases: List<String>,
sql: String,
private val endpoints: List<Endpoint>,
private val dialects: List<Dialect>
Expand All @@ -59,7 +58,7 @@ class SqlResourceType(
private val simpleSelectQuery = SimpleSelectQuery(GroovyTemplateGenerator(sql))

override fun aliases(): List<String> {
return aliases
return listOf(simpleSelectQuery.properties()["name"]!!)
}

override fun path(): List<String> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class MarkdownFile(private val name: String, private val text: String) : File {

private var currentTag: String = ""
private val map = LinkedHashMap<String, String>()
private var key = 1

override fun visit(text: Text) {
if (text.parent is Heading && (text.parent as Heading).level >= 3) {
Expand All @@ -75,7 +76,7 @@ class MarkdownFile(private val name: String, private val text: String) : File {

override fun visit(fencedCodeBlock: FencedCodeBlock) {
if (fencedCodeBlock.fenceLength == 4) {
map[currentTag] = fencedCodeBlock.literal.trim()
map[key++.toString()] = fencedCodeBlock.literal.trim()
}
}

Expand Down
Loading

0 comments on commit b44d65b

Please sign in to comment.