Skip to content

Commit 6956db8

Browse files
authored
Merge pull request #8 from krisrice/main
Converted pdf to md for easier view and maintenance
2 parents 4ae67c6 + ef2de19 commit 6956db8

File tree

3 files changed

+286
-19
lines changed

3 files changed

+286
-19
lines changed

Quick-SQL-Grammar.pdf

-21.8 KB
Binary file not shown.

README.md

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,25 @@
22

33
<!-- TOC -->
44

5-
- [Overview](#overview)
6-
- [Installation](#installation)
7-
- [Building Locally](#building-locally)
8-
- [Running Tests](#running-tests)
9-
- [Running the Example CLI](#running-the-example-cli)
10-
- [Translating QSQL into Oracle SQL Data Definition Language (DDL)](#translating-qsql-into-oracle-sql-data-definition-language-ddl)
11-
- [DDL NodeJS ECMA Script Module (ESM) Example](#ddl-nodejs-ecma-script-module-esm-example)
12-
- [DDL NodeJS Common JS (CJS) Example](#ddl-nodejs-common-js-cjs-example)
13-
- [DDL Browser ECMA Script Module (ESM) Example](#ddl-browser-ecma-script-module-esm-example)
14-
- [DDL Browser Universal Module Definition (UMD) Example](#ddl-browser-universal-module-definition-umd-example)
15-
- [Transforming Quick SQL into an Entity-Relationship Diagram (ERD)](#transforming-quick-sql-into-an-entity-relationship-diagram-erd)
16-
- [Prerequisites](#prerequisites)
17-
- [ERD Browser ESM Example](#erd-browser-esm-example)
18-
- [ERD Browser UMD Example](#erd-browser-umd-example)
19-
- [ERD Theming](#erd-theming)
20-
- [Contributing](#contributing)
21-
- [Security](#security)
22-
- [License](#license)
5+
- [QuickSQL](#quicksql)
6+
- [Overview](#overview)
7+
- [Installation](#installation)
8+
- [Building Locally](#building-locally)
9+
- [Running Tests](#running-tests)
10+
- [Running the Example CLI](#running-the-example-cli)
11+
- [Translating QSQL into Oracle SQL Data Definition Language (DDL)](#translating-qsql-into-oracle-sql-data-definition-language-ddl)
12+
- [DDL NodeJS ECMA Script Module (ESM) Example](#ddl-nodejs-ecma-script-module-esm-example)
13+
- [DDL NodeJS Common JS (CJS) Example](#ddl-nodejs-common-js-cjs-example)
14+
- [DDL Browser ECMA Script Module (ESM) Example](#ddl-browser-ecma-script-module-esm-example)
15+
- [DDL Browser Universal Module Definition (UMD) Example](#ddl-browser-universal-module-definition-umd-example)
16+
- [Transforming Quick SQL into an Entity-Relationship Diagram (ERD)](#transforming-quick-sql-into-an-entity-relationship-diagram-erd)
17+
- [Prerequisites](#prerequisites)
18+
- [ERD Browser ESM Example](#erd-browser-esm-example)
19+
- [ERD Browser UMD Example](#erd-browser-umd-example)
20+
- [ERD Theming](#erd-theming)
21+
- [Contributing](#contributing)
22+
- [Security](#security)
23+
- [License](#license)
2324

2425
<!-- /TOC -->
2526

@@ -81,7 +82,7 @@ npm run example-cli -- ./test/department_employees.quicksql
8182
The QSQL to DDL translator is the product's core component, It allows users
8283
to transform a QSQL string into an Oracle SQL string.
8384
84-
The Quick SQL Syntax is documented [here](./Quick-SQL-Grammar.pdf)
85+
The Quick SQL Syntax is documented [here](./quicksql.md)
8586
8687
See below for examples of how to use this library.
8788

quicksql.md

Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
# Quick SQL Grammar
2+
3+
# Table of Contents
4+
1. [Datatypes](#datatypes)
5+
2. [Table Directives](#table-directives)
6+
3. [Column Directives](#column-Directives)
7+
4. [Views](#views)
8+
5. [Settings](#settings)
9+
6. [Grammar](#grammar)
10+
11+
12+
# Datatypes<a name="datatypes"></a>
13+
| Type | DB Type |
14+
| -------- | ------- |
15+
| num, number | NUMBER |
16+
| int, integer | INTEGER |
17+
| d, date | Date |
18+
| ts, timestamp | TIMESTAMP |
19+
| tstz, tswtz, timestamp with local time zone | TIMESTAMP WITH LOCAL TIMEZONE |
20+
| char, vc, varchar, varchar2, string | Varchar2(4000) |
21+
| vcNNN,vc(NNN) | Varchar2(NNN) |
22+
| vc32k | Varchar2(32767) |
23+
| clob | clob |
24+
| blob | blob |
25+
|json | CLOB CHECK (<Column Name> IS JSON) |
26+
| file | Adds a BLOB column and _FILENAME, _CHARSET, _MIMETYPE, _LASTUPD columns that enhance the ability for file download via a browser |
27+
28+
# Table Directives<a name="table-directives"></a>
29+
| Directive | Description |
30+
| -------- | ------- |
31+
| /api | enerate PL/SQL package API to query, insert, update, and delete data within a table. Adds Oracle auditing, by default AUDIT ALL ON [TABLE NAME]. |
32+
| /audit | Adds Oracle auditing, by default AUDIT ALL ON [TABLE NAME].|
33+
| /auditcols, /audit cols, /audit columns | Automatically adds an UPDATED, UPDATED_BY, INSERTED, and INSERTED_BY columns and the trigger logic to set column values. |
34+
| /colprefix | Prefix all columns of a given table with this value. Automatically adds an underscore if not provided. |
35+
| /compress, /compressed | Table will be created compressed. |
36+
| /insert NN | Generate NN SQL INSERT statement(s) with random data, for example: /INSERT 20. (Maximum = 1000) |
37+
| /rest | Generate REST enablement of the table using Oracle REST Data Services (ORDS) |
38+
| /select | Generate SQL SELECT statement after generating data for each table |
39+
| /unique | Generate table level unique constraint |
40+
41+
42+
43+
# Column Directives<a name="column-directives"></a>
44+
| Directive | Description |
45+
| -------- | ------- |
46+
| /idx, /index, /indexed | Creates a non unique index |
47+
| /unique | Creates a unique constraint |
48+
| /check | Creates a check constraint with comma or white space delimited values e.g. /check Yes, No |
49+
| /constant | When generating data set this column to a constant value. For example /constant NYC. |
50+
| /default | Adds default value if the column is null |
51+
| /values | Comma separated list of values to use when generating data. For example /values 1, 2, 3, 4 or /values Yes, No. |
52+
| /upper | Forces column values to upper case |
53+
| /lower | Forces column values to lower case |
54+
| /nn, /not null | Adds a not null constraint on the column |
55+
| /between | Adds a between check constraint on the column, for example /between 1 and 100 |
56+
| /hidden, /invisible | Hidden columns are not displayed using select * from table. |
57+
| /references, /reference, /fk | Foreign key references e.g. /references table_name. Note you can reference tables that are not part of your model. |
58+
| /pk | Identifies column as the primary key of the table. It is recommended not manually specify primary keys and let this app create primary key columns automatically. |
59+
| --, [ comments ] | Enclose comments using square brackets or using dash dash syntax |
60+
61+
# Views<a name="views"></a>
62+
### Syntax:
63+
`view [view_name] [table name] [table name]...`
64+
65+
Ensure the view name contains no spaces, ensure the table names contain no spaces. Delimit table names by a space or comma.
66+
### Example:
67+
`dept dname loc emp ename job view dept_emp emp dept`
68+
69+
This syntax restricts views to conjunctive queries (i.e. containing equijoin predicates) only.
70+
71+
# Settings<a name="settings"></a>
72+
73+
You can enter inline settings to explicitly set SQL syntax generation options. Alternatively, you can click Settings at the top of the right pane to
74+
declaratively set the generation options.
75+
76+
Entering settings directly into the Quick SQL Shorthand pane ensures the same SQL generation options are utilized even if you download the script and later paste it back. For example, enter the following to prefix all table names with TEST and generate for schema OBE:
77+
78+
`# settings = { prefix: "test", schema: "OBE" }.`
79+
Alternatively, enter each setting on a separate line for the same result:
80+
81+
`# prefix: "test"`
82+
83+
`# schema: "OBE"`
84+
85+
Note: The settings must start on a new line and begin with # settings = to enter multiple settings, or # to enter a single setting per line. All values are case insensitive. Brackets, spaces, and commas can be added for clarity but are ignored. To have all settings generated use # verbose: true.
86+
87+
88+
#### ` # apex: true | false `
89+
##### Default : false
90+
This setting controls the syntax generated to support audit columns. Specifically if audit columns are enabled triggers are generated to maintain the user creating a row and the user last updating a row. When enabled the following function is used:
91+
92+
`coalesce(sys_context('APEX$SESSION','APP_USER'),user)`
93+
94+
When not enabled the following function is used: `user`
95+
96+
97+
98+
#### `# api: true | false`
99+
##### Default : false
100+
Generate PL/SQL APIs on all tables for create, insert, update, delete and query.
101+
102+
#### `# auditcols: true | false`
103+
##### Default : false
104+
Adds an additional created, created_by, updated and updated_by columns to every table created.
105+
106+
#### `# compress: true | false`
107+
##### Default : false
108+
When enabled creates all tables compressed.
109+
110+
#### `# createdByCol: "created_by_user"`
111+
##### Default : created_by
112+
When Audit Columns are enabled the default column used to track the user who created a row is CREATED_BY. Use this setting to override default audit column name.
113+
114+
#### `# createdCol: "created_date"`
115+
##### Default : created
116+
When Audit Columns are enabled the default column used to track the user who created a row is CREATED. Use this setting to override default audit column name.
117+
118+
#### `# date: "timestamp with local time zone"`
119+
##### Default : date
120+
By default all DATE columns created using the Oracle DATE datatype. Use this setting to override this default. Valid values are:
121+
date, timestamp, timestamp with time zone,TSWTZ, timestamp with local time zone, TSWLTZ.
122+
123+
#### `# db: "19c"`
124+
##### Default : 21c
125+
Specifies the database version the syntax should be compatible with. Valid values are: **11g**, **12c**, **19c**, **21c**
126+
127+
#### `# drop: true| false`
128+
##### Default : false
129+
Include SQL commands to drop each database object created.
130+
131+
#### `# language: "EN"`
132+
##### Default : EN
133+
Generate data used for insert statements using this language. The default is English. Supported languages include: **EN**, **DE**, **KO**, **JA**
134+
135+
#### `# longVC: true| false`
136+
##### Default : false
137+
Allow longer identifiers to be used for database object names. Longer identifiers allow the maximum length a VARCHAR2 column datatype will be 32767 characters. When not set the maximum length of a VARCHAR2 column datatype will be 4000 characters.
138+
139+
#### `# ondelete: "cascade"`
140+
##### Default : false
141+
This setting controls how foreign key ON DELETE settings. Valid values include: **cascade**, **restrict**, **set null**
142+
143+
#### `# overrideSettings: true| false`
144+
##### Default : false
145+
When enabled all application settings set via the user interface console are ignored and only settings set in the script will be used.
146+
147+
#### `# PK: "identity"`
148+
##### Default : identity
149+
Determines how the primary key will be set. Primary keys can be set using SYS_GUID, identity column or sequence. Valid values include:**guid**, **seq**, **identity**, **none**
150+
151+
#### `# prefix: "foo"`
152+
##### Default :
153+
Database object prefix. An underscore will be appended if not provided.
154+
155+
#### `# prefixPKwithTname: true | false `
156+
##### Default : false
157+
Prefix primary key database table columns with name of table. For example the primary key of the EMPLOYEE table would be EMPLOYEE_ID. Without setting the name of implicitly created primary key columns will be ID.
158+
159+
#### `# genPK: true | false `
160+
##### Default : true
161+
Prefix primary key database table columns with name of table. For example the primary key of the EMPLOYEE table would be EMPLOYEE_ID. Without setting the name of implicitly created primary key columns will be ID.
162+
163+
#### `# resetsettings `
164+
##### Default :
165+
Resets all application settings to default values. When included all application settings currently active for your session will be ignored.
166+
167+
#### `# rowkey: true | false `
168+
##### Default : false
169+
For each table created add a ROW_KEY column that generates an alphanumeric identifier. Values of the ROW_KEY column will be set by generated database table trigger logic.
170+
171+
#### `# tenantID: true | false `
172+
##### Default : false
173+
For each table add a TENANT_ID column to support mutil-tenant applications. The value of this column is simply added to the table, maintaining this value will need to be provided by the developer.
174+
175+
#### `# rowVersion: true | false`
176+
##### Default : false
177+
For each table generated add a ROW_VERSION column that increments by 1 for each update. When enabled database table trigger logic will be generated to increment row versions on update.
178+
179+
#### `# schema: "scott"`
180+
##### Default :
181+
Prefix object names with a schema name. The default is no schema prefix for object names.
182+
183+
#### `# semantics: "char"`
184+
##### Default :
185+
You can choose no column semantics, or **BYTE** or **CHAR** semantics.
186+
Examples:
187+
188+
`varchar2(4000), varchar2(4000 byte), varchar2(4000 char)`
189+
190+
191+
#### `# updatedByCol: "updated_by_user"`
192+
##### Default : updated_ by
193+
When enabling audit columns use this setting to override default audit column name.
194+
195+
#### `# updatedCol: "updated_dt"`
196+
##### Default : updated
197+
When enabling audit columns use this setting to override default audit column name.
198+
199+
#### `# verbose: true | false`
200+
##### Default : false
201+
Show all settings, not just settings that are different from the default.
202+
203+
204+
## Grammar<a name="grammar"></a>
205+
```
206+
qddl::= stmt+
207+
stmt::= tree
208+
| view
209+
| '#' individual_setting
210+
| 'settings' '=' '{' individual_setting ( ',' individual_setting )* '}'
211+
view::= 'view' view_name table_name+
212+
view_name::= identifier
213+
table_name::= identifier
214+
column_name::= identifier
215+
tree::= node+
216+
217+
tableNode::= indentation tableName tableDirective*
218+
columnNode::= indentation columnName columnDirective* datatype*
219+
indentation::= INDENT | DEDENT | SAMELEVEL
220+
tableDirective::= '/'
221+
('api'
222+
|'audit'|'auditcols'|'audit cols'|'audit columns'
223+
|'colprefix'
224+
|'compress'|'compressed'
225+
|'insert' integer
226+
|'rest'
227+
|'select'
228+
|'unique' )
229+
columnDirective::= '/'
230+
('idx'|'index'|'indexed'
231+
|'unique'
232+
|'check'
233+
|'constant'
234+
|'default'
235+
|'values'
236+
|'upper'
237+
|'lower'
238+
|'nn'|'not null'
239+
|'between'
240+
|'hidden'|'invisible'
241+
|'references'|'reference'
242+
|'fk'|'pk' )
243+
datatype::=
244+
'num'|'number'
245+
|'int'|'integer'
246+
|'d'|'date'
247+
|'ts'|'timestamp'
248+
|'tstz'|'tswtz'|'timestamp' 'with' 'local' 'time' 'zonechar'
249+
|'vc'|'varchar'|'varchar2'|'string'
250+
|'vc' integer | 'vc' '(' integer ')'
251+
| 'vc32k'
252+
| 'clob'|'blob'|'jsonfile'
253+
individual_setting::=
254+
( 'apex'|'api'|'audit'
255+
|'cols'|'compress'|'createdbycol'|'createdcol'
256+
|'date'|'db'|'drop'
257+
|'language'|'longvc'
258+
|'ondelete'|'overridesettings'
259+
|'pk'|'prefix'|'prefixpkwithtname'
260+
|'genpk'
261+
|'resetsettings'|'rowkey'
262+
|'tenantid'|'rowversion'
263+
|'schema'|'semantics'
264+
|'updatedbycol'|'updatedcolverbose' ) ':' (string_literal| 'true' | 'false')
265+
```
266+

0 commit comments

Comments
 (0)