2022-08-12 21:08:20 +03:00
|
|
|
/- ast
|
2022-10-21 20:44:14 +03:00
|
|
|
!:
|
2023-05-02 20:33:46 +03:00
|
|
|
:: a library for parsing urQL tapes
|
2023-08-01 00:19:32 +03:00
|
|
|
:: (parse:parse(default-database '<db>') "<script>")
|
|
|
|
|_ default-database=@tas
|
2022-08-29 21:29:37 +03:00
|
|
|
::
|
2023-11-26 01:27:09 +03:00
|
|
|
:: +strip-cmnts: strip block comments from tape
|
|
|
|
::
|
|
|
|
:: Crash
|
|
|
|
:: comment block mismatch line <n>
|
|
|
|
::
|
|
|
|
++ strip-cmnts
|
|
|
|
|= p=tape
|
|
|
|
=/ a=@ 0
|
|
|
|
=/ b=tape ~
|
|
|
|
=/ c=(list @) (flop (fand ~['\0a'] p))
|
|
|
|
|- ^- tape
|
|
|
|
?~ p b
|
|
|
|
?~ c
|
|
|
|
?: &(=(a 1) =("/*" (scag 2 `tape`p))) $(p ~)
|
|
|
|
$(p ~, b (weld p b))
|
|
|
|
?: =("*/" (scag 2 (slag (add 1 i.c) `tape`p)))
|
|
|
|
%= $
|
|
|
|
p (scag i.c `tape`p)
|
|
|
|
a (add a 1)
|
|
|
|
b ?.(=(a 0) b (weld (slag (add 3 i.c) `tape`p) b))
|
|
|
|
c t.c
|
|
|
|
==
|
|
|
|
?: =("/*" (scag 2 (slag (add 1 i.c) `tape`p)))
|
|
|
|
%= $
|
|
|
|
p (scag i.c `tape`p)
|
|
|
|
a ~| "comment block mismatch line {<(lent c)>}" (sub a 1)
|
|
|
|
c t.c
|
|
|
|
==
|
|
|
|
?. =(a 0) $(p (scag i.c `tape`p), c t.c)
|
|
|
|
%= $
|
|
|
|
p (scag i.c `tape`p)
|
|
|
|
b (weld (slag (add 1 i.c) `tape`p) b)
|
|
|
|
c t.c
|
|
|
|
==
|
|
|
|
::
|
2023-05-12 00:30:15 +03:00
|
|
|
:: +parse: parse urQL script, emitting list of high level AST structures
|
2023-05-02 20:33:46 +03:00
|
|
|
++ parse
|
2023-11-01 21:50:17 +03:00
|
|
|
|= raw-script=tape
|
2023-06-06 03:47:20 +03:00
|
|
|
^- (list command:ast)
|
2023-11-26 01:27:09 +03:00
|
|
|
=/ script=tape (strip-cmnts raw-script)
|
2023-06-06 03:47:20 +03:00
|
|
|
=/ commands `(list command:ast)`~
|
2023-08-01 00:19:32 +03:00
|
|
|
=/ script-length (lent script)
|
|
|
|
=/ displacement 0
|
2023-05-02 20:33:46 +03:00
|
|
|
=/ parse-command ;~ pose
|
|
|
|
(cold %alter-index ;~(plug whitespace (jester 'alter') whitespace (jester 'index')))
|
|
|
|
(cold %alter-namespace ;~(plug whitespace (jester 'alter') whitespace (jester 'namespace')))
|
|
|
|
(cold %alter-table ;~(plug whitespace (jester 'alter') whitespace (jester 'table')))
|
|
|
|
(cold %create-database ;~(plug whitespace (jester 'create') whitespace (jester 'database')))
|
|
|
|
(cold %create-namespace ;~(plug whitespace (jester 'create') whitespace (jester 'namespace')))
|
|
|
|
(cold %create-table ;~(plug whitespace (jester 'create') whitespace (jester 'table')))
|
|
|
|
(cold %create-view ;~(plug whitespace (jester 'create') whitespace (jester 'view')))
|
|
|
|
(cold %create-index ;~(plug whitespace (jester 'create'))) :: must be last of creates
|
|
|
|
(cold %delete ;~(plug whitespace (jester 'delete') whitespace (jester 'from')))
|
|
|
|
(cold %delete ;~(plug whitespace (jester 'delete')))
|
|
|
|
(cold %drop-database ;~(plug whitespace (jester 'drop') whitespace (jester 'database')))
|
|
|
|
(cold %drop-index ;~(plug whitespace (jester 'drop') whitespace (jester 'index')))
|
|
|
|
(cold %drop-namespace ;~(plug whitespace (jester 'drop') whitespace (jester 'namespace')))
|
|
|
|
(cold %drop-table ;~(plug whitespace (jester 'drop') whitespace (jester 'table')))
|
|
|
|
(cold %drop-view ;~(plug whitespace (jester 'drop') whitespace (jester 'view')))
|
|
|
|
(cold %grant ;~(plug whitespace (jester 'grant')))
|
|
|
|
(cold %insert ;~(plug whitespace (jester 'insert') whitespace (jester 'into')))
|
|
|
|
(cold %merge ;~(plug whitespace (jester 'merge') whitespace (jester 'into')))
|
|
|
|
(cold %merge ;~(plug whitespace (jester 'merge') whitespace (jester 'from')))
|
|
|
|
(cold %merge ;~(plug whitespace (jester 'merge')))
|
|
|
|
(cold %query ;~(plug whitespace (jester 'from')))
|
|
|
|
(cold %query ;~(plug whitespace ;~(pfix (jester 'select') (funk "select" (easy ' ')))))
|
|
|
|
(cold %revoke ;~(plug whitespace (jester 'revoke')))
|
|
|
|
(cold %truncate-table ;~(plug whitespace (jester 'truncate') whitespace (jester 'table')))
|
|
|
|
(cold %update ;~(pfix whitespace (jester 'update')))
|
|
|
|
(cold %with ;~(plug whitespace (jester 'with')))
|
|
|
|
==
|
2023-08-01 00:19:32 +03:00
|
|
|
=/ dummy ~|('Default database name is not a proper term' (scan (trip default-database) sym))
|
2023-05-02 20:33:46 +03:00
|
|
|
:: main loop
|
|
|
|
::
|
|
|
|
|-
|
2023-08-01 00:19:32 +03:00
|
|
|
?~ script (flop commands)
|
2023-05-02 20:33:46 +03:00
|
|
|
=/ check-empty u.+3:q.+3:(whitespace [[1 1] script])
|
|
|
|
?: =(0 (lent q.q:check-empty)) :: trailing whitespace after last end-command (;)
|
|
|
|
(flop commands)
|
2023-08-01 00:19:32 +03:00
|
|
|
~| "script error after displacement {<displacement>}"
|
|
|
|
=/ command-nail u.+3:q.+3:(parse-command [[1 1] script])
|
2023-06-06 03:47:20 +03:00
|
|
|
?- `urql-command`p.command-nail
|
2022-09-07 22:25:00 +03:00
|
|
|
%alter-index
|
2023-08-01 00:19:32 +03:00
|
|
|
~| "alter index error: {<(scag 100 q.q.command-nail)>} ..."
|
2023-05-02 20:33:46 +03:00
|
|
|
=/ index-nail (parse-alter-index [[1 1] q.q.command-nail])
|
|
|
|
=/ parsed (wonk index-nail)
|
|
|
|
?: ?=([[@ @ @ @ @] [@ @ @ @ @] @] [parsed]) ::"alter index action"
|
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:index-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-05-02 20:33:46 +03:00
|
|
|
commands
|
2023-06-06 03:47:20 +03:00
|
|
|
[`command:ast`(alter-index:ast %alter-index -.parsed +<.parsed ~ +>.parsed) commands]
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
|
|
|
?: ?=([[@ @ @ @ @] [@ @ @ @ @] [[@ @ @] %~]] [parsed]) ::"alter index single column"
|
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:index-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-05-02 20:33:46 +03:00
|
|
|
commands
|
2023-06-06 03:47:20 +03:00
|
|
|
[`command:ast`(alter-index:ast %alter-index -.parsed +<.parsed +>.parsed %rebuild) commands]
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
|
|
|
?: ?=([[@ @ @ @ @] [@ @ @ @ @] * @] [parsed]) ::"alter index columns action"
|
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:index-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-05-02 20:33:46 +03:00
|
|
|
commands
|
2023-06-06 03:47:20 +03:00
|
|
|
[`command:ast`(alter-index:ast %alter-index -.parsed +<.parsed +>-.parsed +>+.parsed) commands]
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
|
|
|
?: ?=([[@ @ @ @ @] [@ @ @ @ @] *] [parsed]) ::"alter index multiple columns"
|
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:index-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-05-02 20:33:46 +03:00
|
|
|
commands
|
2023-06-06 03:47:20 +03:00
|
|
|
[`command:ast`(alter-index:ast %alter-index -.parsed +<.parsed +>.parsed %rebuild) commands]
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
|
|
|
~|("Cannot parse alter-index {<p.q.command-nail>}" !!)
|
2022-09-07 22:25:00 +03:00
|
|
|
%alter-namespace
|
2023-08-01 00:19:32 +03:00
|
|
|
~| "alter namespace error: {<(scag 100 q.q.command-nail)>} ..."
|
2023-05-02 20:33:46 +03:00
|
|
|
=/ namespace-nail (parse-alter-namespace [[1 1] q.q.command-nail])
|
|
|
|
=/ parsed (wonk namespace-nail)
|
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:namespace-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-05-02 20:33:46 +03:00
|
|
|
commands
|
2023-10-23 22:23:17 +03:00
|
|
|
[`command:ast`(alter-namespace:ast %alter-namespace -<.parsed ->.parsed +<.parsed +>+>+<.parsed +>+>+>.parsed ~) commands]
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
2022-09-08 23:48:02 +03:00
|
|
|
%alter-table
|
2023-08-01 00:19:32 +03:00
|
|
|
~| "alter table error: {<(scag 100 q.q.command-nail)>} ..."
|
2023-05-02 20:33:46 +03:00
|
|
|
=/ table-nail (parse-alter-table [[1 1] q.q.command-nail])
|
|
|
|
=/ parsed (wonk table-nail)
|
|
|
|
?: =(+<.parsed %alter-column)
|
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:table-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-05-02 20:33:46 +03:00
|
|
|
commands
|
2023-10-23 22:23:17 +03:00
|
|
|
[`command:ast`(alter-table:ast %alter-table -.parsed +>.parsed ~ ~ ~ ~ ~) commands]
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
|
|
|
?: =(+<.parsed %add-column)
|
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:table-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-05-02 20:33:46 +03:00
|
|
|
commands
|
2023-10-23 22:23:17 +03:00
|
|
|
[`command:ast`(alter-table:ast %alter-table -.parsed ~ +>.parsed ~ ~ ~ ~) commands]
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
|
|
|
?: =(+<.parsed %drop-column)
|
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:table-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-05-02 20:33:46 +03:00
|
|
|
commands
|
2023-10-23 22:23:17 +03:00
|
|
|
[`command:ast`(alter-table:ast %alter-table -.parsed ~ ~ +>.parsed ~ ~ ~) commands]
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
|
|
|
?: =(+<.parsed %add-fk)
|
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:table-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-05-02 20:33:46 +03:00
|
|
|
commands
|
2023-10-23 22:23:17 +03:00
|
|
|
[`command:ast`(alter-table:ast %alter-table -.parsed ~ ~ ~ (build-foreign-keys [-.parsed +>.parsed]) ~ ~) commands]
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
|
|
|
?: =(+<.parsed %drop-fk)
|
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:table-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-05-02 20:33:46 +03:00
|
|
|
commands
|
2023-10-23 22:23:17 +03:00
|
|
|
[`command:ast`(alter-table:ast %alter-table -.parsed ~ ~ ~ ~ +>.parsed ~) commands]
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
|
|
|
~|("Cannot parse table {<p.q.command-nail>}" !!)
|
2022-08-12 21:08:20 +03:00
|
|
|
%create-database
|
2023-08-01 00:19:32 +03:00
|
|
|
~| "create database error: {<(scag 40 q.q.command-nail)>} ..."
|
2023-05-02 20:33:46 +03:00
|
|
|
~| 'Create database must be only statement in script'
|
|
|
|
?> =((lent commands) 0)
|
|
|
|
%= $
|
|
|
|
script ""
|
|
|
|
commands
|
2023-10-23 22:23:17 +03:00
|
|
|
[`command:ast`(create-database:ast %create-database p.u.+3:q.+3:(parse-face [[1 1] q.q.command-nail]) ~) commands]
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
2022-08-12 21:08:20 +03:00
|
|
|
%create-index
|
2023-08-01 00:19:32 +03:00
|
|
|
~| "create index error: {<(scag 100 q.q.command-nail)>} ..."
|
2023-05-02 20:33:46 +03:00
|
|
|
=/ index-nail (parse-create-index [[1 1] q.q.command-nail])
|
|
|
|
=/ parsed (wonk index-nail)
|
|
|
|
?: ?=([@ [* *]] [parsed]) ::"create index ..."
|
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:index-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-05-02 20:33:46 +03:00
|
|
|
commands
|
2023-06-06 03:47:20 +03:00
|
|
|
[`command:ast`(create-index:ast %create-index -.parsed +<.parsed %.n %.n +>.parsed) commands]
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
|
|
|
?: ?=([[@ @] [* *]] [parsed])
|
|
|
|
?: =(-<.parsed %unique) ::"create unique index ..."
|
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:index-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-05-02 20:33:46 +03:00
|
|
|
commands
|
2023-06-06 03:47:20 +03:00
|
|
|
[`command:ast`(create-index:ast %create-index ->.parsed +<.parsed %.y %.n +>.parsed) commands]
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
|
|
|
?: =(-<.parsed %clustered) ::"create clustered index ..."
|
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:index-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-05-02 20:33:46 +03:00
|
|
|
commands
|
2023-06-06 03:47:20 +03:00
|
|
|
[`command:ast`(create-index:ast %create-index ->.parsed +<.parsed %.n %.y +>.parsed) commands]
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
2023-08-01 00:19:32 +03:00
|
|
|
?: =(-<.parsed %look-up) ::"create look-up index ..."
|
2023-05-02 20:33:46 +03:00
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:index-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-05-02 20:33:46 +03:00
|
|
|
commands
|
2023-06-06 03:47:20 +03:00
|
|
|
[`command:ast`(create-index:ast %create-index ->.parsed +<.parsed %.n %.n +>.parsed) commands]
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
|
|
|
~|("Cannot parse index {<p.q.command-nail>}" !!)
|
|
|
|
?: ?=([[@ @ @] [* *]] [parsed])
|
|
|
|
?: =(->-.parsed %clustered) ::"create unique clustered index ..."
|
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:index-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-05-02 20:33:46 +03:00
|
|
|
commands
|
2023-06-06 03:47:20 +03:00
|
|
|
[`command:ast`(create-index:ast %create-index ->+.parsed +<.parsed %.y %.y +>.parsed) commands]
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
2023-08-01 00:19:32 +03:00
|
|
|
?: =(->-.parsed %look-up) ::"create unique look-up index ..."
|
2023-05-02 20:33:46 +03:00
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:index-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-05-02 20:33:46 +03:00
|
|
|
commands
|
2023-06-06 03:47:20 +03:00
|
|
|
[`command:ast`(create-index:ast %create-index ->+.parsed +<.parsed %.y %.n +>.parsed) commands]
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
|
|
|
~|("Cannot parse index {<p.q.command-nail>}" !!)
|
|
|
|
~|("Cannot parse index {<p.q.command-nail>}" !!)
|
2022-08-12 21:08:20 +03:00
|
|
|
%create-namespace
|
2023-08-01 00:19:32 +03:00
|
|
|
~| "create namespace error: {<(scag 40 q.q.command-nail)>} ..."
|
2023-05-02 20:33:46 +03:00
|
|
|
=/ create-namespace-nail (parse-create-namespace [[1 1] q.q.command-nail])
|
|
|
|
=/ parsed (wonk create-namespace-nail)
|
|
|
|
?@ parsed
|
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:create-namespace-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-10-23 22:23:17 +03:00
|
|
|
commands [`command:ast`(create-namespace:ast %create-namespace default-database parsed ~) commands]
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:create-namespace-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-10-23 22:23:17 +03:00
|
|
|
commands [`command:ast`(create-namespace:ast %create-namespace -.parsed +.parsed ~) commands]
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
2022-08-12 21:08:20 +03:00
|
|
|
%create-table
|
2023-08-01 00:19:32 +03:00
|
|
|
~| "create table error: {<(scag 100 q.q.command-nail)>} ..."
|
2023-05-02 20:33:46 +03:00
|
|
|
=/ table-nail (parse-create-table [[1 1] q.q.command-nail])
|
|
|
|
=/ parsed (wonk table-nail)
|
|
|
|
?: ?=([* * [@ @ *]] parsed)
|
|
|
|
%= $ :: no foreign keys
|
|
|
|
script q.q.u.+3.q:table-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-05-02 20:33:46 +03:00
|
|
|
commands
|
2023-10-23 22:23:17 +03:00
|
|
|
[`command:ast`(create-table:ast %create-table -.parsed +<.parsed +>+<.parsed +>+>.parsed ~ ~) commands]
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:table-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-05-02 20:33:46 +03:00
|
|
|
commands
|
2023-10-23 22:23:17 +03:00
|
|
|
[`command:ast`(create-table:ast %create-table -.parsed +<.parsed +>->-.parsed +>->+.parsed (build-foreign-keys [-.parsed +>+.parsed]) ~) commands]
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
2022-08-12 21:08:20 +03:00
|
|
|
%create-view
|
2023-08-01 00:19:32 +03:00
|
|
|
~| "create view error: {<(scag 100 q.q.command-nail)>} ..."
|
2023-05-02 20:33:46 +03:00
|
|
|
!!
|
2023-03-03 20:35:01 +03:00
|
|
|
%delete
|
2023-08-01 00:19:32 +03:00
|
|
|
~| "delete error: {<(scag 100 q.q.command-nail)>} ..."
|
2023-05-02 20:33:46 +03:00
|
|
|
=/ delete-nail (parse-delete [[1 1] q.q.command-nail])
|
|
|
|
=/ parsed (wonk delete-nail)
|
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:delete-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-05-02 20:33:46 +03:00
|
|
|
commands
|
2023-06-06 03:47:20 +03:00
|
|
|
[`command:ast`(transform:ast %transform ~ [(produce-delete parsed) ~ ~]) commands]
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
2022-08-16 22:18:14 +03:00
|
|
|
%drop-database
|
2023-08-01 00:19:32 +03:00
|
|
|
~| "drop database error: {<(scag 100 q.q.command-nail)>} ..."
|
2023-05-02 20:33:46 +03:00
|
|
|
=/ drop-database-nail (parse-drop-database [[1 1] q.q.command-nail])
|
|
|
|
=/ parsed (wonk drop-database-nail)
|
|
|
|
?@ parsed :: name
|
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:drop-database-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-06-06 03:47:20 +03:00
|
|
|
commands [`command:ast`(drop-database:ast %drop-database parsed %.n) commands]
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
|
|
|
~| "Cannot parse drop-database {<parsed>}"
|
|
|
|
?: ?=([@ @] parsed) :: force name
|
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:drop-database-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-06-06 03:47:20 +03:00
|
|
|
commands [`command:ast`(drop-database:ast %drop-database +.parsed %.y) commands]
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
|
|
|
!!
|
|
|
|
%drop-index
|
2023-08-01 00:19:32 +03:00
|
|
|
~| "drop index error: {<(scag 100 q.q.command-nail)>} ..."
|
2023-05-02 20:33:46 +03:00
|
|
|
=/ drop-index-nail (parse-drop-index [[1 1] q.q.command-nail])
|
|
|
|
=/ parsed (wonk drop-index-nail)
|
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:drop-index-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-06-06 03:47:20 +03:00
|
|
|
commands [`command:ast`(drop-index:ast %drop-index -.parsed +.parsed) commands]
|
2022-09-04 20:53:13 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
%drop-namespace
|
2023-08-01 00:19:32 +03:00
|
|
|
~| "drop namespace error: {<(scag 100 q.q.command-nail)>} ..."
|
2023-05-02 20:33:46 +03:00
|
|
|
=/ drop-namespace-nail (parse-drop-namespace [[1 1] q.q.command-nail])
|
|
|
|
=/ parsed (wonk drop-namespace-nail)
|
|
|
|
?@ parsed :: name
|
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:drop-namespace-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-10-23 22:23:17 +03:00
|
|
|
commands [`command:ast`(drop-namespace:ast %drop-namespace default-database parsed %.n ~) commands]
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
|
|
|
?: ?=([@ @] parsed) :: force name
|
|
|
|
?: =(%force -.parsed)
|
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:drop-namespace-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-10-23 22:23:17 +03:00
|
|
|
commands [`command:ast`(drop-namespace:ast %drop-namespace default-database +.parsed %.y ~) commands]
|
2022-08-17 20:10:50 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
%= $ :: db.name
|
|
|
|
script q.q.u.+3.q:drop-namespace-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-10-23 22:23:17 +03:00
|
|
|
commands [`command:ast`(drop-namespace:ast %drop-namespace -.parsed +.parsed %.n ~) commands]
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
|
|
|
~| "Cannot parse drop-namespace {<parsed>}"
|
|
|
|
?: ?=([* [@ @]] parsed) :: force db.name
|
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:drop-namespace-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-10-23 22:23:17 +03:00
|
|
|
commands [`command:ast`(drop-namespace:ast %drop-namespace +<.parsed +>.parsed %.y ~) commands]
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
2022-09-25 18:52:01 +03:00
|
|
|
!!
|
2023-05-02 20:33:46 +03:00
|
|
|
%drop-table
|
2023-08-01 00:19:32 +03:00
|
|
|
~| "drop table error: {<(scag 100 q.q.command-nail)>} ..."
|
2023-05-02 20:33:46 +03:00
|
|
|
=/ drop-table-nail (drop-table-or-view [[1 1] q.q.command-nail])
|
|
|
|
=/ parsed (wonk drop-table-nail)
|
|
|
|
?: ?=([@ @ @ @ @ @] parsed) :: force qualified table name
|
2023-01-12 00:09:20 +03:00
|
|
|
%= $
|
2023-05-02 20:33:46 +03:00
|
|
|
script q.q.u.+3.q:drop-table-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-05-02 20:33:46 +03:00
|
|
|
commands
|
2023-10-23 22:23:17 +03:00
|
|
|
[`command:ast`(drop-table:ast %drop-table +.parsed %.y ~) commands]
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
|
|
|
?: ?=([@ @ @ @ @] parsed) :: qualified table name
|
2023-01-05 21:17:42 +03:00
|
|
|
%= $
|
2023-05-02 20:33:46 +03:00
|
|
|
script q.q.u.+3.q:drop-table-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-05-02 20:33:46 +03:00
|
|
|
commands
|
2023-10-23 22:23:17 +03:00
|
|
|
[`command:ast`(drop-table:ast %drop-table parsed %.n ~) commands]
|
2023-01-05 21:17:42 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
~|("Cannot parse drop-table {<parsed>}" !!)
|
|
|
|
%drop-view
|
2023-08-01 00:19:32 +03:00
|
|
|
~| "drop view error: {<(scag 100 q.q.command-nail)>} ..."
|
2023-05-02 20:33:46 +03:00
|
|
|
=/ drop-view-nail (drop-table-or-view [[1 1] q.q.command-nail])
|
|
|
|
=/ parsed (wonk drop-view-nail)
|
|
|
|
?: ?=([@ @ @ @ @ @] parsed) :: force qualified view
|
2023-01-05 21:17:42 +03:00
|
|
|
%= $
|
2023-05-02 20:33:46 +03:00
|
|
|
script q.q.u.+3.q:drop-view-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-05-02 20:33:46 +03:00
|
|
|
commands
|
2023-06-06 03:47:20 +03:00
|
|
|
[`command:ast`(drop-view:ast %drop-view +.parsed %.y) commands]
|
2023-01-05 21:17:42 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
?: ?=([@ @ @ @ @] parsed) :: qualified view
|
2023-01-12 00:09:20 +03:00
|
|
|
%= $
|
2023-05-02 20:33:46 +03:00
|
|
|
script q.q.u.+3.q:drop-view-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-05-02 20:33:46 +03:00
|
|
|
commands
|
2023-06-06 03:47:20 +03:00
|
|
|
[`command:ast`(drop-view:ast %drop-view parsed %.n) commands]
|
2023-01-12 00:09:20 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
~|("Cannot parse drop-view {<parsed>}" !!)
|
|
|
|
%grant
|
2023-08-01 00:19:32 +03:00
|
|
|
~| "grant error: {<(scag 100 q.q.command-nail)>} ..."
|
2023-05-02 20:33:46 +03:00
|
|
|
=/ grant-nail (parse-grant [[1 1] q.q.command-nail])
|
|
|
|
=/ parsed (wonk grant-nail)
|
|
|
|
?: ?=([@ [@ [@ %~]] [@ @]] [parsed]) ::"grant adminread to ~sampel-palnet on database db"
|
2023-01-12 00:09:20 +03:00
|
|
|
%= $
|
2023-05-02 20:33:46 +03:00
|
|
|
script q.q.u.+3.q:grant-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-05-02 20:33:46 +03:00
|
|
|
commands
|
2023-06-06 03:47:20 +03:00
|
|
|
[`command:ast`(grant:ast %grant -.parsed +<+.parsed +>.parsed) commands]
|
2023-01-12 00:09:20 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
?: ?=([@ @ [@ @]] [parsed]) ::"grant adminread to parent on database db"
|
2023-02-15 22:20:47 +03:00
|
|
|
%= $
|
2023-05-02 20:33:46 +03:00
|
|
|
script q.q.u.+3.q:grant-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-05-02 20:33:46 +03:00
|
|
|
commands
|
2023-06-06 03:47:20 +03:00
|
|
|
[`command:ast`(grant:ast %grant -.parsed +<.parsed +>.parsed) commands]
|
2023-02-15 22:20:47 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
?: ?=([@ [@ [@ *]] [@ *]] [parsed]) ::"grant Readwrite to ~zod,~bus,~nec,~sampel-palnet on namespace db.ns"
|
|
|
|
%= $ ::"grant adminread to ~zod,~bus,~nec,~sampel-palnet on namespace ns" (ns previously cooked)
|
|
|
|
script q.q.u.+3.q:grant-nail ::"grant Readwrite to ~zod,~bus,~nec,~sampel-palnet on db.ns.table"
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-05-02 20:33:46 +03:00
|
|
|
commands
|
2023-06-06 03:47:20 +03:00
|
|
|
[`command:ast`(grant:ast %grant -.parsed +<+.parsed +>.parsed) commands]
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
|
|
|
?: ?=([@ @ [@ [@ *]]] [parsed]) ::"grant readonly to siblings on namespace db.ns"
|
|
|
|
%= $ ::"grant readwrite to moons on namespace ns" (ns previously cooked)
|
|
|
|
script q.q.u.+3.q:grant-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-05-02 20:33:46 +03:00
|
|
|
commands
|
2023-06-06 03:47:20 +03:00
|
|
|
[`command:ast`(grant:ast %grant -.parsed +<.parsed +>.parsed) commands]
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
|
|
|
~|("Cannot parse grant {<parsed>}" !!)
|
|
|
|
%insert
|
2023-08-01 00:19:32 +03:00
|
|
|
~| "insert error: {<(scag 100 q.q.command-nail)>} ..."
|
2023-05-02 20:33:46 +03:00
|
|
|
=/ insert-nail (parse-insert [[1 1] q.q.command-nail])
|
|
|
|
=/ parsed (wonk insert-nail)
|
2023-05-17 03:34:14 +03:00
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:insert-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-05-17 03:34:14 +03:00
|
|
|
commands
|
2023-06-06 03:47:20 +03:00
|
|
|
[`command:ast`(transform:ast %transform ~ [(produce-insert parsed) ~ ~]) commands]
|
2023-05-17 03:34:14 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
%merge
|
2023-08-01 00:19:32 +03:00
|
|
|
~| "merge error: {<(scag 100 q.q.command-nail)>} ..."
|
2023-05-02 20:33:46 +03:00
|
|
|
=/ merge-nail (parse-merge [[1 1] q.q.command-nail])
|
|
|
|
=/ parsed (wonk merge-nail)
|
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:merge-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-05-02 20:33:46 +03:00
|
|
|
commands
|
2023-06-06 03:47:20 +03:00
|
|
|
[`command:ast`(transform:ast %transform ~ [(produce-merge parsed) ~ ~]) commands]
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
|
|
|
%query
|
2023-08-01 00:19:32 +03:00
|
|
|
~| "query error: {<(scag 100 q.q.command-nail)>} ..."
|
2023-05-02 20:33:46 +03:00
|
|
|
=/ query-nail (parse-query [[1 1] q.q.command-nail])
|
|
|
|
=/ parsed (wonk query-nail)
|
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:query-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-05-02 20:33:46 +03:00
|
|
|
commands
|
2023-06-06 03:47:20 +03:00
|
|
|
[`command:ast`(transform:ast %transform ~ [(produce-query parsed) ~ ~]) commands]
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
|
|
|
%revoke
|
2023-08-01 00:19:32 +03:00
|
|
|
~| "revoke error: {<(scag 100 q.q.command-nail)>} ..."
|
2023-05-02 20:33:46 +03:00
|
|
|
=/ revoke-nail (parse-revoke [[1 1] q.q.command-nail])
|
|
|
|
=/ parsed (wonk revoke-nail)
|
|
|
|
?: ?=([@ [@ [@ %~]] [@ @]] [parsed]) ::"revoke adminread from ~sampel-palnet on database db"
|
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:revoke-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-05-02 20:33:46 +03:00
|
|
|
commands
|
2023-06-06 03:47:20 +03:00
|
|
|
[`command:ast`(revoke:ast %revoke -.parsed +<+.parsed +>.parsed) commands]
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
|
|
|
?: ?=([@ @ [@ @]] [parsed]) ::"revoke adminread from parent on database db"
|
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:revoke-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-05-02 20:33:46 +03:00
|
|
|
commands
|
2023-06-06 03:47:20 +03:00
|
|
|
[`command:ast`(revoke:ast %revoke -.parsed +<.parsed +>.parsed) commands]
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
|
|
|
?: ?=([@ [@ [@ *]] [@ *]] [parsed]) ::"revoke Readwrite from ~zod,~bus,~nec,~sampel-palnet on namespace db.ns"
|
|
|
|
%= $ ::"revoke adminread from ~zod,~bus,~nec,~sampel-palnet on namespace ns" (ns previously cooked)
|
|
|
|
script q.q.u.+3.q:revoke-nail ::"revoke Readwrite from ~zod,~bus,~nec,~sampel-palnet on db.ns.table"
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-05-02 20:33:46 +03:00
|
|
|
commands
|
2023-06-06 03:47:20 +03:00
|
|
|
[`command:ast`(revoke:ast %revoke -.parsed +<+.parsed +>.parsed) commands]
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
|
|
|
?: ?=([@ @ [@ [@ *]]] [parsed]) ::"revoke readonly from siblings on namespace db.ns"
|
|
|
|
%= $ ::"revoke readwrite from moons on namespace ns" (ns previously cooked)
|
|
|
|
script q.q.u.+3.q:revoke-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-05-02 20:33:46 +03:00
|
|
|
commands
|
2023-06-06 03:47:20 +03:00
|
|
|
[`command:ast`(revoke:ast %revoke -.parsed +<.parsed +>.parsed) commands]
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
|
|
|
~|("Cannot parse revoke {<parsed>}" !!)
|
|
|
|
%truncate-table
|
2023-08-01 00:19:32 +03:00
|
|
|
~| "truncate table error: {<(scag 100 q.q.command-nail)>} ..."
|
2023-05-02 20:33:46 +03:00
|
|
|
=/ truncate-table-nail (parse-truncate-table [[1 1] q.q.command-nail])
|
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:truncate-table-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-05-02 20:33:46 +03:00
|
|
|
commands
|
2023-06-06 03:47:20 +03:00
|
|
|
[`command:ast`(truncate-table:ast %truncate-table (wonk truncate-table-nail)) commands]
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
|
|
|
%update
|
2023-08-01 00:19:32 +03:00
|
|
|
~| "update error: {<(scag 100 q.q.command-nail)>} ..."
|
2023-05-02 20:33:46 +03:00
|
|
|
=/ update-nail (parse-update [[1 1] q.q.command-nail])
|
|
|
|
=/ parsed (wonk update-nail)
|
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:update-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-05-02 20:33:46 +03:00
|
|
|
commands
|
2023-06-06 03:47:20 +03:00
|
|
|
[`command:ast`(transform:ast %transform ~ [(produce-update parsed) ~ ~]) commands]
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
|
|
|
%with
|
2023-08-01 00:19:32 +03:00
|
|
|
~| "with error: {<(scag 100 q.q.command-nail)>} ..."
|
2023-05-02 20:33:46 +03:00
|
|
|
=/ with-nail (parse-with [[1 1] q.q.command-nail])
|
|
|
|
=/ parsed (wonk with-nail)
|
2023-05-16 22:59:29 +03:00
|
|
|
?: =(+<.parsed %delete)
|
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:with-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-06-06 03:47:20 +03:00
|
|
|
commands [`command:ast`(transform:ast %transform (produce-ctes -.parsed) [(produce-delete +>.parsed) ~ ~]) commands]
|
2023-05-16 22:59:29 +03:00
|
|
|
==
|
2023-05-17 03:34:14 +03:00
|
|
|
?: =(+<.parsed %insert)
|
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:with-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-06-06 03:47:20 +03:00
|
|
|
commands [`command:ast`(transform:ast %transform (produce-ctes -.parsed) [(produce-insert +>.parsed) ~ ~]) commands]
|
2023-05-17 03:34:14 +03:00
|
|
|
==
|
2023-05-16 22:59:29 +03:00
|
|
|
?: =(+<.parsed %merge)
|
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:with-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-06-06 03:47:20 +03:00
|
|
|
commands [`command:ast`(transform:ast %transform (produce-ctes -.parsed) [(produce-merge +>.parsed) ~ ~]) commands]
|
2023-05-16 22:59:29 +03:00
|
|
|
==
|
|
|
|
?: =(+<.parsed %query)
|
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:with-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-06-06 03:47:20 +03:00
|
|
|
commands [`command:ast`(transform:ast %transform (produce-ctes -.parsed) [(produce-query +>.parsed) ~ ~]) commands]
|
2023-05-16 22:59:29 +03:00
|
|
|
==
|
|
|
|
?: =(+<.parsed %update)
|
|
|
|
%= $
|
|
|
|
script q.q.u.+3.q:with-nail
|
2023-08-01 00:19:32 +03:00
|
|
|
displacement (sub script-length (lent script))
|
2023-06-06 03:47:20 +03:00
|
|
|
commands [`command:ast`(transform:ast %transform (produce-ctes -.parsed) [(produce-update +>.parsed) ~ ~]) commands]
|
2023-05-16 22:59:29 +03:00
|
|
|
==
|
|
|
|
~|("cannot parse 'with': {<parsed>}" !!)
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
2023-06-06 03:47:20 +03:00
|
|
|
+$ urql-command
|
2023-05-02 20:33:46 +03:00
|
|
|
$%
|
|
|
|
%alter-index
|
|
|
|
%alter-namespace
|
|
|
|
%alter-table
|
|
|
|
%create-database
|
|
|
|
%create-index
|
|
|
|
%create-namespace
|
|
|
|
%create-table
|
|
|
|
%create-view
|
|
|
|
%delete
|
|
|
|
%drop-database
|
|
|
|
%drop-index
|
|
|
|
%drop-namespace
|
|
|
|
%drop-table
|
|
|
|
%drop-view
|
|
|
|
%grant
|
|
|
|
%insert
|
|
|
|
%merge
|
|
|
|
%query
|
|
|
|
%revoke
|
|
|
|
%truncate-table
|
|
|
|
%update
|
|
|
|
%with
|
|
|
|
==
|
|
|
|
::
|
|
|
|
:: helper types
|
|
|
|
::
|
|
|
|
+$ interim-key
|
|
|
|
$:
|
|
|
|
%interim-key
|
2023-08-01 00:19:32 +03:00
|
|
|
clustered=?
|
2023-05-02 20:33:46 +03:00
|
|
|
columns=(list ordered-column:ast)
|
|
|
|
==
|
|
|
|
+$ parens ?(%pal %par)
|
|
|
|
+$ raw-predicate-component ?(parens predicate-component:ast predicate:ast)
|
|
|
|
+$ raw-predicate-component2 ?(parens predicate-component:ast)
|
|
|
|
+$ group-by-list (list grouping-column:ast)
|
|
|
|
+$ order-by-list (list ordering-column:ast)
|
|
|
|
::
|
|
|
|
:: parser rules and helpers
|
|
|
|
::
|
|
|
|
++ whitespace ~+ (star ;~(pose gah (just '\09') (just '\0d')))
|
|
|
|
++ prn-less-soz ~+ ;~(less (just `@`39) (just `@`127) (shim 32 256))
|
|
|
|
::
|
|
|
|
:: +crub-no-text: crub:so without text parsing
|
|
|
|
++ crub-no-text
|
|
|
|
~+
|
|
|
|
;~ pose
|
|
|
|
(cook |=(det=date `dime`[%da (year det)]) when:so)
|
|
|
|
::
|
|
|
|
%+ cook
|
|
|
|
|= [a=(list [p=?(%d %h %m %s) q=@]) b=(list @)]
|
|
|
|
=+ rop=`tarp`[0 0 0 0 b]
|
|
|
|
|- ^- dime
|
|
|
|
?~ a
|
|
|
|
[%dr (yule rop)]
|
|
|
|
?- p.i.a
|
|
|
|
%d $(a t.a, d.rop (add q.i.a d.rop))
|
|
|
|
%h $(a t.a, h.rop (add q.i.a h.rop))
|
|
|
|
%m $(a t.a, m.rop (add q.i.a m.rop))
|
|
|
|
%s $(a t.a, s.rop (add q.i.a s.rop))
|
|
|
|
==
|
|
|
|
;~ plug
|
|
|
|
%+ most
|
|
|
|
dot
|
|
|
|
;~ pose
|
|
|
|
;~(pfix (just 'd') (stag %d dim:ag))
|
|
|
|
;~(pfix (just 'h') (stag %h dim:ag))
|
|
|
|
;~(pfix (just 'm') (stag %m dim:ag))
|
|
|
|
;~(pfix (just 's') (stag %s dim:ag))
|
|
|
|
==
|
|
|
|
;~(pose ;~(pfix ;~(plug dot dot) (most dot qix:ab)) (easy ~))
|
|
|
|
==
|
|
|
|
::
|
|
|
|
(stag %p fed:ag)
|
|
|
|
==
|
|
|
|
::
|
|
|
|
:: +jester: match a cord, case agnostic, thanks ~tinnus-napbus
|
|
|
|
++ jester
|
|
|
|
|= daf=@t
|
|
|
|
|= tub=nail
|
|
|
|
~+
|
|
|
|
=+ fad=daf
|
|
|
|
|- ^- (like @t)
|
|
|
|
?: =(`@`0 daf)
|
|
|
|
[p=p.tub q=[~ u=[p=fad q=tub]]]
|
|
|
|
=+ n=(end 3 daf)
|
|
|
|
?. ?& ?=(^ q.tub)
|
|
|
|
?| =(n i.q.tub)
|
|
|
|
&((lte 97 n) (gte 122 n) =((sub n 32) i.q.tub))
|
|
|
|
&((lte 65 n) (gte 90 n) =((add 32 n) i.q.tub))
|
2023-02-15 22:20:47 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
|
|
|
(fail tub)
|
|
|
|
$(p.tub (lust i.q.tub p.tub), q.tub t.q.tub, daf (rsh 3 daf))
|
|
|
|
::
|
|
|
|
:: qualified objects, usually table or view
|
|
|
|
:: maximally qualified by @p.database.namespace
|
|
|
|
:: minimally qualified by namespace
|
|
|
|
::
|
|
|
|
:: +cook-qualified-2object: namespace.object-name
|
|
|
|
++ cook-qualified-2object
|
|
|
|
|= a=*
|
|
|
|
?@ a
|
2023-08-01 00:19:32 +03:00
|
|
|
(qualified-object:ast %qualified-object ~ default-database 'dbo' a)
|
|
|
|
(qualified-object:ast %qualified-object ~ default-database -.a +.a)
|
2023-05-02 20:33:46 +03:00
|
|
|
::
|
|
|
|
:: +cook-qualified-3object: database.namespace.object-name
|
|
|
|
++ cook-qualified-3object
|
|
|
|
|= a=*
|
|
|
|
?: ?=([@ @ @] a) :: db.ns.name
|
|
|
|
(qualified-object:ast %qualified-object ~ -.a +<.a +>.a)
|
|
|
|
?: ?=([@ @ @ @] a) :: db..name
|
|
|
|
(qualified-object:ast %qualified-object ~ -.a 'dbo' +>+.a)
|
|
|
|
?: ?=([@ @] a) :: ns.name
|
2023-08-01 00:19:32 +03:00
|
|
|
(qualified-object:ast %qualified-object ~ default-database -.a +.a)
|
2023-05-02 20:33:46 +03:00
|
|
|
?@ a :: name
|
2023-08-01 00:19:32 +03:00
|
|
|
(qualified-object:ast %qualified-object ~ default-database 'dbo' a)
|
2023-05-02 20:33:46 +03:00
|
|
|
~|("cannot parse qualified-object {<a>}" !!)
|
|
|
|
::
|
|
|
|
:: +cook-qualified-object: @p.database.namespace.object-name
|
|
|
|
++ cook-qualified-object
|
|
|
|
|= a=*
|
|
|
|
?: ?=([@ @ @ @] a)
|
|
|
|
?: =(+<.a '.')
|
|
|
|
(qualified-object:ast %qualified-object ~ -.a 'dbo' +>+.a) :: db..name
|
|
|
|
(qualified-object:ast %qualified-object `-.a +<.a +>-.a +>+.a) :: ~firsub.db.ns.name
|
|
|
|
?: ?=([@ @ @ @ @ @] a) :: ~firsub.db..name
|
|
|
|
(qualified-object:ast %qualified-object `-.a +>-.a 'dbo' +>+>+.a)
|
|
|
|
?: ?=([@ @ @] a)
|
|
|
|
(qualified-object:ast %qualified-object ~ -.a +<.a +>.a) :: db.ns.name
|
|
|
|
?: ?=([@ @] a) :: ns.name
|
2023-08-01 00:19:32 +03:00
|
|
|
(qualified-object:ast %qualified-object ~ default-database -.a +.a)
|
2023-05-02 20:33:46 +03:00
|
|
|
?@ a :: name
|
2023-08-01 00:19:32 +03:00
|
|
|
(qualified-object:ast %qualified-object ~ default-database 'dbo' a)
|
2023-05-02 20:33:46 +03:00
|
|
|
~|("cannot parse qualified-object {<a>}" !!)
|
|
|
|
:: +qualified-namespace: database.namespace
|
|
|
|
++ qualified-namespace
|
2023-08-01 00:19:32 +03:00
|
|
|
|= [a=* default-database=@t]
|
2023-05-02 20:33:46 +03:00
|
|
|
?: ?=([@ @] [a])
|
|
|
|
a
|
2023-08-01 00:19:32 +03:00
|
|
|
[default-database a]
|
2023-05-02 21:21:45 +03:00
|
|
|
++ parse-qualified-2-name ;~(pose ;~(pfix whitespace ;~((glue dot) sym sym)) parse-face)
|
2023-05-02 20:33:46 +03:00
|
|
|
::
|
|
|
|
:: +parse-qualified-3: database.namespace.object-name
|
2023-05-02 21:21:45 +03:00
|
|
|
++ parse-qualified-3 ;~ pose
|
2023-05-02 20:33:46 +03:00
|
|
|
;~((glue dot) sym sym sym)
|
|
|
|
;~(plug sym dot dot sym)
|
|
|
|
;~((glue dot) sym sym)
|
|
|
|
sym
|
|
|
|
==
|
2023-05-02 21:21:45 +03:00
|
|
|
++ parse-qualified-3object (cook cook-qualified-3object ;~(pfix whitespace parse-qualified-3))
|
2023-05-02 20:33:46 +03:00
|
|
|
++ parse-qualified-object (cook cook-qualified-object ;~(pose ;~((glue dot) parse-ship sym sym sym) ;~(plug parse-ship:parse dot sym dot dot sym) ;~(plug sym dot dot sym) parse-qualified-3))
|
|
|
|
::
|
|
|
|
:: working with atomic value literals
|
|
|
|
::
|
|
|
|
++ cord-literal ~+
|
|
|
|
(cook |=(a=(list @t) [%t (crip a)]) (ifix [soq soq] (star ;~(pose (cold '\'' (jest '\\\'')) prn-less-soz))))
|
|
|
|
++ numeric-parser ;~ pose
|
|
|
|
(stag %ud (full dem:ag)) :: formatted @ud
|
|
|
|
(stag %ud (full dim:ag)) :: unformatted @ud, no leading 0s
|
|
|
|
(stag %ub (full bay:ag)) :: formatted @ub, no leading 0s
|
|
|
|
(stag %ux ;~(pfix (jest '0x') (full hex:ag))) :: formatted @ux
|
|
|
|
(full tash:so) :: @sd or @sx
|
2023-08-01 00:19:32 +03:00
|
|
|
;~(pfix dot (stag %rs (full royl-rs:so))) :: @rs
|
2023-05-02 20:33:46 +03:00
|
|
|
(stag %rd (full royl-rd:so)) :: @rd
|
|
|
|
(stag %uw (full wiz:ag)) :: formatted @uw base-64 unsigned
|
|
|
|
==
|
|
|
|
++ non-numeric-parser ;~ pose
|
|
|
|
cord-literal
|
|
|
|
;~(pose ;~(pfix sig crub-no-text) crub-no-text) :: @da, @dr, @p
|
|
|
|
(stag %is ;~(pfix (just '.') bip:ag)) :: @is
|
|
|
|
(stag %if ;~(pfix (just '.') lip:ag)) :: @if
|
|
|
|
(stag %f ;~(pose (cold & (jester 'y')) (cold | (jester 'n')))) :: @if
|
|
|
|
==
|
|
|
|
++ cook-numbers :: works for insert values
|
|
|
|
|= a=(list @t)
|
2023-08-01 00:19:32 +03:00
|
|
|
~|("error on numeric parser {<a>} " (scan a numeric-parser))
|
2023-05-02 20:33:46 +03:00
|
|
|
++ sear-numbers :: works for predicate values
|
|
|
|
|= a=(list @t)
|
|
|
|
=/ parsed (numeric-parser [[1 1] a])
|
|
|
|
?~ q.parsed ~
|
|
|
|
(some (wonk parsed))
|
|
|
|
++ numeric-characters ~+
|
|
|
|
:: including base-64 characters
|
|
|
|
(star ;~(pose (shim 48 57) (shim 65 90) (shim 97 122) dot fas hep lus sig tis))
|
|
|
|
++ parse-value-literal ;~ pose
|
|
|
|
non-numeric-parser
|
|
|
|
(sear sear-numbers numeric-characters) :: all numeric parsers
|
|
|
|
==
|
|
|
|
++ insert-value ~+ ;~ pose
|
|
|
|
(cold [%default %default] (jester 'default'))
|
|
|
|
;~(pose non-numeric-parser (cook cook-numbers numeric-characters))
|
|
|
|
==
|
2023-05-02 21:21:45 +03:00
|
|
|
++ get-value-literal ~+ ;~ pose :: changing to ifix here slowed down test cases
|
2023-05-02 20:33:46 +03:00
|
|
|
;~(sfix ;~(pfix whitespace parse-value-literal) whitespace)
|
|
|
|
;~(pfix whitespace parse-value-literal)
|
|
|
|
;~(sfix parse-value-literal whitespace)
|
|
|
|
parse-value-literal
|
|
|
|
==
|
|
|
|
++ cook-literal-list
|
|
|
|
:: 1. all literal types must be the same
|
|
|
|
::
|
|
|
|
:: 2. (a-co:co d) each atom to tape, weld tapes with delimiter, crip final tape
|
|
|
|
:: bad reason for (2): cannot ?=(expression ...) when expression includes a list
|
|
|
|
::
|
2023-08-01 00:19:32 +03:00
|
|
|
|= a=(list dime)
|
2023-05-02 20:33:46 +03:00
|
|
|
~+
|
|
|
|
=/ literal-type=@tas -<.a
|
|
|
|
=/ b a
|
|
|
|
=/ literal-list=tape ~
|
|
|
|
|-
|
|
|
|
?: =(b ~) (value-literal-list:ast %value-literal-list literal-type (crip literal-list))
|
|
|
|
?: =(-<.b literal-type)
|
|
|
|
?: =(literal-list ~)
|
|
|
|
$(b +.b, literal-list (a-co:co ->.b))
|
|
|
|
$(b +.b, literal-list (weld (weld (a-co:co ->.b) ";") literal-list))
|
|
|
|
~|("cannot parse literal-list {<a>}" !!)
|
2023-05-02 21:21:45 +03:00
|
|
|
++ value-literal-list
|
2023-05-02 20:33:46 +03:00
|
|
|
(cook cook-literal-list ;~(pose ;~(pfix whitespace (ifix [pal par] (more com get-value-literal))) (ifix [pal par] (more com get-value-literal))))
|
|
|
|
++ parse-insert-value ;~ pose
|
|
|
|
;~(pfix whitespace ;~(sfix insert-value whitespace))
|
|
|
|
;~(pfix whitespace insert-value)
|
|
|
|
;~(sfix insert-value whitespace)
|
|
|
|
insert-value
|
2023-01-05 21:17:42 +03:00
|
|
|
==
|
2022-10-05 23:00:47 +03:00
|
|
|
::
|
2023-05-02 20:33:46 +03:00
|
|
|
:: used for various commands
|
2022-10-05 23:00:47 +03:00
|
|
|
::
|
2023-05-02 20:33:46 +03:00
|
|
|
++ cook-column
|
|
|
|
|= a=*
|
2023-08-01 00:19:32 +03:00
|
|
|
?. ?=([@ @] [a]) ~|("cannot parse column {<a>}" !!)
|
|
|
|
?@ +.a
|
|
|
|
(column:ast %column -.a (crip (slag 1 (trip +.a))))
|
2023-05-02 20:33:46 +03:00
|
|
|
~|("cannot parse column {<a>}" !!)
|
|
|
|
++ cook-ordered-column
|
|
|
|
|= a=*
|
|
|
|
?@ a
|
|
|
|
(ordered-column:ast %ordered-column a %.y)
|
|
|
|
?: ?=([@ @] [a])
|
|
|
|
?: =(+.a %asc)
|
|
|
|
(ordered-column:ast %ordered-column -.a %.y)
|
|
|
|
(ordered-column:ast %ordered-column -.a %.n)
|
|
|
|
~|("cannot parse ordered-column {<a>}" !!)
|
|
|
|
++ cook-referential-integrity
|
|
|
|
|= a=*
|
|
|
|
?: ?=([[@ @] @ @] [a]) :: <type> cascade, <type> cascade
|
|
|
|
?: =(%delete -<.a)
|
|
|
|
?: =(%update +<.a)
|
|
|
|
~[%delete-cascade %update-cascade]
|
|
|
|
!!
|
|
|
|
?: =(%update -<.a)
|
|
|
|
?: =(%delete +<.a)
|
|
|
|
~[%delete-cascade %update-cascade]
|
|
|
|
!!
|
|
|
|
!!
|
|
|
|
?: ?=([@ @] [a]) :: <type> cascade
|
|
|
|
?: =(-.a %delete) [%delete-cascade ~] [%update-cascade ~]
|
|
|
|
?: ?=([[@ @] @ @ [@ %~] @] [a]) :: <type> cascade, <type> no action
|
|
|
|
?: =(-<.a %delete) [%delete-cascade ~] [%update-cascade ~]
|
|
|
|
?: ?=([[@ @ [@ %~] @] @ @] [a]) :: <type> no action, <type> cascade
|
|
|
|
?: =(+<.a %delete) [%delete-cascade ~] [%update-cascade ~]
|
|
|
|
?: ?=([@ [@ %~]] a) :: <type> no action
|
|
|
|
~
|
|
|
|
?: ?=([[@ @ [@ %~] @] @ @ [@ %~] @] a) :: <type> no action, <type> no action
|
|
|
|
~
|
|
|
|
~|("cannot parse ordered-column {<a>}" !!)
|
|
|
|
++ end-or-next-command ;~ plug
|
|
|
|
(cold %end-command ;~(pose ;~(plug whitespace mic) whitespace mic))
|
|
|
|
(easy ~)
|
2022-10-05 23:00:47 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
++ alias
|
|
|
|
%+ cook
|
|
|
|
|=(a=tape (rap 3 ^-((list ,@) a)))
|
2023-08-08 05:21:32 +03:00
|
|
|
;~(plug alf (star ;~(pose nud alf hep)))
|
2023-05-02 20:33:46 +03:00
|
|
|
++ parse-alias ;~(pfix whitespace alias)
|
|
|
|
++ parse-face ;~(pfix whitespace sym)
|
2023-05-02 21:21:45 +03:00
|
|
|
++ face-list ;~(pfix whitespace (ifix [pal par] (more com ;~(pose ;~(sfix parse-face whitespace) parse-face))))
|
|
|
|
++ ordering ;~(pfix whitespace ;~(pose (jester 'asc') (jester 'desc')))
|
2023-08-01 00:19:32 +03:00
|
|
|
++ clustering ;~(pfix whitespace ;~(pose (jester 'clustered') (jester 'look-up')))
|
2023-05-02 21:21:45 +03:00
|
|
|
++ ordered-column-list
|
2023-05-02 20:33:46 +03:00
|
|
|
;~(pfix whitespace (ifix [pal par] (more com (cook cook-ordered-column ;~(pose ;~(sfix ;~(plug parse-face ordering) whitespace) ;~(plug parse-face ordering) ;~(sfix parse-face whitespace) parse-face)))))
|
2023-05-02 21:21:45 +03:00
|
|
|
++ parse-ship ;~(pfix sig fed:ag)
|
|
|
|
++ ship-list (more com ;~(pose ;~(sfix ;~(pfix whitespace parse-ship) whitespace) ;~(pfix whitespace parse-ship) ;~(sfix parse-ship whitespace) parse-ship))
|
|
|
|
++ on-database ;~(plug (jester 'database') parse-face)
|
|
|
|
++ on-namespace
|
2023-08-01 00:19:32 +03:00
|
|
|
;~(plug (jester 'namespace') (cook |=(a=* (qualified-namespace [a default-database])) parse-qualified-2-name))
|
2023-05-02 21:21:45 +03:00
|
|
|
++ grant-object
|
2023-05-02 20:33:46 +03:00
|
|
|
;~(pfix whitespace ;~(pfix (jester 'on') ;~(pfix whitespace ;~(pose on-database on-namespace parse-qualified-3object))))
|
|
|
|
++ parse-aura ~+
|
|
|
|
=/ root-aura ;~ pose
|
2023-08-01 00:19:32 +03:00
|
|
|
(jest '@c') :: UTF-32
|
|
|
|
(jest '@da') :: date
|
|
|
|
(jest '@dr') :: timespan
|
|
|
|
(jest '@f') :: loobean
|
|
|
|
(jest '@if') :: IPv4 address
|
|
|
|
(jest '@is') :: IPv6 address
|
|
|
|
(jest '@p') :: ship name
|
|
|
|
(jest '@q') :: phonemic base, unscrambled
|
|
|
|
(jest '@rh') :: half precision (16 bits)
|
|
|
|
(jest '@rs') :: single precision (32 bits)
|
|
|
|
(jest '@rd') :: double precision (64 bits)
|
|
|
|
(jest '@rq') :: quad precision (128 bits)
|
|
|
|
(jest '@sb') :: signed binary
|
|
|
|
(jest '@sd') :: signed decimal
|
|
|
|
(jest '@sv') :: signed base32
|
|
|
|
(jest '@sw') :: signed base64
|
|
|
|
(jest '@sx') :: signed hexadecimal
|
|
|
|
(jest '@t') :: UTF-8 text (cord)
|
|
|
|
(jest '@ta') :: ASCII text (knot)
|
|
|
|
(jest '@tas') :: ASCII text symbol (term)
|
|
|
|
(jest '@ub') :: unsigned binary
|
|
|
|
(jest '@ud') :: unsigned decimal
|
|
|
|
(jest '@uv') :: unsigned base32
|
|
|
|
(jest '@uw') :: unsigned base64
|
|
|
|
(jest '@ux') :: unsigned hexadecimal
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
|
|
|
;~ pose
|
|
|
|
;~(plug root-aura (shim 'A' 'J'))
|
|
|
|
root-aura
|
2022-10-05 23:00:47 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
++ aggregate-name
|
|
|
|
|= name=@t
|
|
|
|
^- @t
|
|
|
|
(crip (cass (trip name)))
|
2023-05-02 21:21:45 +03:00
|
|
|
++ column-defintion-list
|
2023-05-02 20:33:46 +03:00
|
|
|
=/ column-definition ;~ plug
|
|
|
|
sym
|
|
|
|
;~(pfix whitespace parse-aura)
|
|
|
|
==
|
|
|
|
(more com (cook cook-column ;~(pose ;~(pfix whitespace ;~(sfix column-definition whitespace)) ;~(sfix column-definition whitespace) ;~(pfix whitespace column-definition) column-definition)))
|
|
|
|
++ referential-integrity ;~ plug
|
|
|
|
;~(pfix ;~(plug whitespace (jester 'on') whitespace) ;~(pose (jester 'update') (jester 'delete')))
|
|
|
|
;~(pfix whitespace ;~(pose (jester 'cascade') ;~(plug (jester 'no') whitespace (jester 'action'))))
|
2022-10-05 23:00:47 +03:00
|
|
|
==
|
2023-05-02 21:21:45 +03:00
|
|
|
++ column-definitions ;~(pfix whitespace (ifix [pal par] column-defintion-list))
|
|
|
|
++ alter-columns ;~ plug
|
2023-05-02 20:33:46 +03:00
|
|
|
(cold %alter-column ;~(plug whitespace (jester 'alter') whitespace (jester 'column')))
|
|
|
|
column-definitions
|
2022-10-05 23:00:47 +03:00
|
|
|
==
|
2023-05-02 21:21:45 +03:00
|
|
|
++ add-columns ;~ plug
|
2023-05-02 20:33:46 +03:00
|
|
|
(cold %add-column ;~(plug whitespace (jester 'add') whitespace (jester 'column')))
|
|
|
|
column-definitions
|
2022-10-13 18:51:22 +03:00
|
|
|
==
|
2023-05-02 21:21:45 +03:00
|
|
|
++ drop-columns ;~ plug
|
2023-05-02 20:33:46 +03:00
|
|
|
(cold %drop-column ;~(plug whitespace (jester 'drop') whitespace (jester 'column')))
|
|
|
|
face-list
|
2022-10-13 18:51:22 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
++ parse-datum ~+ ;~ pose
|
|
|
|
;~(pose ;~(pfix whitespace parse-qualified-column) parse-qualified-column)
|
|
|
|
;~(pose ;~(pfix whitespace parse-value-literal) parse-value-literal)
|
2022-10-13 18:51:22 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
++ cook-aggregate
|
|
|
|
|= parsed=*
|
|
|
|
[%aggregate -.parsed +.parsed]
|
|
|
|
++ parse-aggregate ;~ pose
|
|
|
|
(cook cook-aggregate ;~(pfix whitespace ;~(plug ;~(sfix parse-alias pal) ;~(sfix get-datum par))))
|
|
|
|
(cook cook-aggregate ;~(plug ;~(sfix parse-alias pal) ;~(sfix get-datum par)))
|
2022-10-05 23:00:47 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
++ cook-selected-aggregate
|
|
|
|
|= parsed=*
|
|
|
|
[%selected-aggregate -.parsed +.parsed]
|
|
|
|
++ parse-selected-aggregate ;~ pose
|
|
|
|
(cook cook-selected-aggregate ;~(pfix whitespace ;~(plug ;~(sfix parse-alias pal) ;~(sfix get-datum par))))
|
|
|
|
(cook cook-selected-aggregate ;~(plug ;~(sfix parse-alias pal) ;~(sfix get-datum par)))
|
|
|
|
==
|
|
|
|
::
|
|
|
|
:: indices
|
|
|
|
::
|
|
|
|
++ cook-primary-key
|
|
|
|
|= a=*
|
|
|
|
~+
|
|
|
|
?@ -.a
|
|
|
|
?: =(-.a 'clustered') (interim-key %interim-key %.y +.a) (interim-key %interim-key %.n +.a)
|
2023-08-01 00:19:32 +03:00
|
|
|
(interim-key %interim-key %.y a)
|
2023-05-02 20:33:46 +03:00
|
|
|
++ cook-foreign-key
|
|
|
|
|= a=*
|
|
|
|
?: ?=([[@ * * [@ @] *] *] [a]) :: foreign key ns.table ... references fk-table ... on action on action
|
|
|
|
(foreign-key:ast %foreign-key -<.a ->-.a ->+<-.a ->+<+.a ->+>.a +.a)
|
|
|
|
?: ?=([[@ [[@ @ @] %~] @ [@ %~]] *] [a]) :: foreign key table ... references fk-table ... on action on action
|
|
|
|
(foreign-key:ast %foreign-key -<.a ->-.a ->+<-.a 'dbo' ->+.a +.a)
|
|
|
|
~|("cannot parse foreign-key {<a>}" !!)
|
|
|
|
++ build-foreign-keys
|
|
|
|
|= a=[table=qualified-object:ast f-keys=(list *)]
|
|
|
|
=/ f-keys +.a
|
|
|
|
=/ foreign-keys `(list foreign-key:ast)`~
|
|
|
|
|-
|
|
|
|
?: =(~ f-keys)
|
|
|
|
(flop foreign-keys)
|
|
|
|
?@ -<.f-keys
|
|
|
|
%= $ :: foreign key table must be in same DB as table
|
|
|
|
foreign-keys [(foreign-key:ast %foreign-key -<.f-keys -.a ->-.f-keys (qualified-object:ast %qualified-object ~ ->+<.a ->+<+>+<.f-keys ->+<+>+>.f-keys) ->+>.f-keys ~) foreign-keys]
|
|
|
|
f-keys +.f-keys
|
|
|
|
==
|
|
|
|
%= $ :: foreign key table must be in same DB as table
|
|
|
|
foreign-keys [(foreign-key:ast %foreign-key -<-.f-keys -.a -<+<.f-keys (qualified-object:ast %qualified-object ~ ->+<.a -<+>->+>-.f-keys -<+>->+>+.f-keys) -<+>+.f-keys ->.f-keys) foreign-keys]
|
|
|
|
f-keys +.f-keys
|
|
|
|
==
|
2023-05-02 21:21:45 +03:00
|
|
|
++ foreign-key-literal ;~(plug whitespace (jester 'foreign') whitespace (jester 'key'))
|
|
|
|
++ foreign-key
|
2023-05-02 20:33:46 +03:00
|
|
|
;~(plug parse-face ordered-column-list ;~(pfix ;~(plug whitespace (jester 'references')) ;~(plug (cook cook-qualified-2object parse-qualified-2-name) face-list)))
|
2023-05-02 21:21:45 +03:00
|
|
|
++ full-foreign-key ;~ pose
|
2023-05-02 20:33:46 +03:00
|
|
|
;~(plug foreign-key (cook cook-referential-integrity ;~(plug referential-integrity referential-integrity)))
|
|
|
|
;~(plug foreign-key (cook cook-referential-integrity ;~(plug referential-integrity referential-integrity)))
|
|
|
|
;~(plug foreign-key (cook cook-referential-integrity referential-integrity))
|
|
|
|
;~(plug foreign-key (cook cook-referential-integrity referential-integrity))
|
|
|
|
foreign-key
|
2022-10-05 23:00:47 +03:00
|
|
|
==
|
2023-05-02 21:21:45 +03:00
|
|
|
++ add-foreign-key ;~ plug
|
2023-05-02 20:33:46 +03:00
|
|
|
(cold %add-fk ;~(plug whitespace (jester 'add')))
|
|
|
|
;~(pfix foreign-key-literal (more com full-foreign-key))
|
2022-10-23 23:12:24 +03:00
|
|
|
==
|
2023-05-02 21:21:45 +03:00
|
|
|
++ drop-foreign-key ;~ plug
|
2023-05-02 20:33:46 +03:00
|
|
|
(cold %drop-fk ;~(plug whitespace (jester 'drop') whitespace (jester 'foreign') whitespace (jester 'key')))
|
|
|
|
face-list
|
2022-10-13 18:51:22 +03:00
|
|
|
==
|
2023-05-02 21:21:45 +03:00
|
|
|
++ primary-key
|
2023-05-02 20:33:46 +03:00
|
|
|
(cook cook-primary-key ;~(pfix ;~(plug whitespace (jester 'primary') whitespace (jester 'key')) ;~(pose ;~(plug clustering ordered-column-list) ordered-column-list)))
|
2022-10-13 18:51:22 +03:00
|
|
|
::
|
2023-05-02 20:33:46 +03:00
|
|
|
:: query object and joins
|
2022-10-13 18:51:22 +03:00
|
|
|
::
|
2023-05-02 20:33:46 +03:00
|
|
|
++ join-stop ;~ pose
|
|
|
|
;~(plug (jester 'where') whitespace)
|
|
|
|
;~(plug (jester 'scalar') whitespace)
|
|
|
|
;~(plug (jester 'group') whitespace)
|
|
|
|
;~(plug (jester 'select') whitespace)
|
|
|
|
;~(plug (jester 'join') whitespace)
|
|
|
|
;~(plug (jester 'left') whitespace)
|
|
|
|
;~(plug (jester 'right') whitespace)
|
|
|
|
;~(plug (jester 'outer') whitespace)
|
|
|
|
;~(plug (jester 'cross') whitespace)
|
|
|
|
;~(plug (jester 'on') whitespace)
|
2022-10-13 18:51:22 +03:00
|
|
|
==
|
2023-05-02 21:21:45 +03:00
|
|
|
++ query-object ;~ pose
|
2023-05-02 20:33:46 +03:00
|
|
|
;~(plug parse-qualified-object ;~(pfix whitespace ;~(pfix (jester 'as') parse-alias)))
|
|
|
|
;~(plug parse-qualified-object ;~(pfix whitespace ;~(less join-stop parse-alias)))
|
|
|
|
parse-qualified-object
|
|
|
|
(stag %query-row ;~(plug face-list ;~(pfix whitespace ;~(pfix (jester 'as') parse-alias))))
|
|
|
|
(stag %query-row ;~(plug face-list ;~(pfix whitespace ;~(less join-stop parse-alias))))
|
|
|
|
(stag %query-row face-list)
|
2022-10-13 18:51:22 +03:00
|
|
|
==
|
2023-05-02 21:21:45 +03:00
|
|
|
++ parse-query-object ;~ pfix
|
2023-05-02 20:33:46 +03:00
|
|
|
whitespace
|
|
|
|
(cook build-query-object query-object)
|
2022-10-16 02:09:57 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
++ parse-join-type ;~ pfix whitespace ;~ pose
|
|
|
|
(cold %join (jester 'join'))
|
|
|
|
(cold %left-join ;~(plug (jester 'left') whitespace (jester 'join')))
|
|
|
|
(cold %right-join ;~(plug (jester 'right') whitespace (jester 'join')))
|
|
|
|
(cold %outer-join-all ;~(plug (jester 'outer') whitespace (jester 'join') whitespace (jester 'all')))
|
|
|
|
(cold %outer-join ;~(plug (jester 'outer') whitespace (jester 'join')))
|
2022-10-17 01:40:25 +03:00
|
|
|
==
|
2022-09-12 22:38:25 +03:00
|
|
|
==
|
2023-05-02 21:21:45 +03:00
|
|
|
++ parse-cross-join-type ;~ pfix
|
2023-05-02 20:33:46 +03:00
|
|
|
whitespace
|
|
|
|
(cold %cross-join ;~(plug (jester 'cross') whitespace (jester 'join')))
|
2022-10-22 22:03:54 +03:00
|
|
|
==
|
2023-05-02 21:21:45 +03:00
|
|
|
++ build-query-object
|
2022-10-22 22:03:54 +03:00
|
|
|
|= parsed=*
|
2023-05-02 20:33:46 +03:00
|
|
|
?: ?=([@ @ @ @ @] parsed)
|
2023-05-15 19:48:28 +03:00
|
|
|
(table-set:ast %table-set parsed ~)
|
2023-05-02 20:33:46 +03:00
|
|
|
?: ?=([[@ @ @ @ @] @] parsed)
|
2023-05-15 19:48:28 +03:00
|
|
|
(table-set:ast %table-set -.parsed `+.parsed)
|
2023-05-02 20:33:46 +03:00
|
|
|
?: =(%query-row -.parsed) parsed
|
|
|
|
~|("cannot parse query-object {<parsed>}" !!)
|
2023-05-02 21:21:45 +03:00
|
|
|
++ parse-cross-joined-object ;~(plug parse-cross-join-type parse-query-object)
|
|
|
|
++ parse-joined-object ;~ plug
|
2023-05-02 20:33:46 +03:00
|
|
|
parse-join-type
|
|
|
|
parse-query-object
|
|
|
|
;~(pfix whitespace ;~(pfix (jester 'on') parse-predicate))
|
2022-10-22 22:03:54 +03:00
|
|
|
==
|
2023-05-02 21:21:45 +03:00
|
|
|
++ parse-object-and-joins ;~ plug
|
2023-05-02 20:33:46 +03:00
|
|
|
parse-query-object
|
|
|
|
;~(pose parse-cross-joined-object (star parse-joined-object))
|
2022-10-22 22:03:54 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
::
|
|
|
|
:: column in "join on" or "where" predicate, qualified or aliased
|
|
|
|
:: indeterminate qualification and aliasing is determined later
|
|
|
|
::
|
|
|
|
++ cook-qualified-column
|
2022-11-07 03:56:54 +03:00
|
|
|
|= a=*
|
2023-05-02 20:33:46 +03:00
|
|
|
~+
|
|
|
|
?: ?=([@ @ @ @ @] a) :: @p.db.ns.object.column
|
|
|
|
(qualified-column:ast %qualified-column (qualified-object:ast %qualified-object `-.a +<.a +>-.a +>+<.a) +>+>.a ~)
|
|
|
|
?: ?=([@ @ @ @ @ @] a) :: @p.db..object.column
|
|
|
|
(qualified-column:ast %qualified-column (qualified-object:ast %qualified-object `-.a +<.a 'dbo' +>+>-.a) +>+>+.a ~)
|
|
|
|
?: ?=([@ @ @ @] a) :: db..object.column; db.ns.object.column
|
|
|
|
?: =(+<.a '.')
|
|
|
|
(qualified-column:ast %qualified-column (qualified-object:ast %qualified-object ~ -.a 'dbo' +>-.a) +>+.a ~)
|
|
|
|
(qualified-column:ast %qualified-column (qualified-object:ast %qualified-object ~ -.a +<.a +>-.a) +>+.a ~)
|
|
|
|
?: ?=([@ @ @] a) :: ns.object.column
|
2023-08-01 00:19:32 +03:00
|
|
|
(qualified-column:ast %qualified-column (qualified-object:ast %qualified-object ~ default-database -.a +<.a) +>.a ~)
|
2023-05-02 20:33:46 +03:00
|
|
|
?: ?=([@ @] a) :: something.column (could be table, table alias or cte)
|
|
|
|
(qualified-column:ast %qualified-column (qualified-object:ast %qualified-object ~ 'UNKNOWN' 'COLUMN' -.a) +.a ~)
|
|
|
|
?@ a :: column, column alias, or cte
|
|
|
|
(qualified-column:ast %qualified-column (qualified-object:ast %qualified-object ~ 'UNKNOWN' 'COLUMN-OR-CTE' a) a ~)
|
|
|
|
~|("cannot parse qualified-column {<a>}" !!)
|
|
|
|
++ parse-column ~+ ;~ pose
|
|
|
|
;~((glue dot) parse-ship sym sym sym sym)
|
|
|
|
;~(plug parse-ship ;~(pfix dot sym) dot dot sym ;~(pfix dot sym))
|
|
|
|
;~((glue dot) sym sym sym sym)
|
|
|
|
;~(plug sym dot ;~(pfix dot sym) ;~(pfix dot sym))
|
|
|
|
;~((glue dot) sym sym sym)
|
|
|
|
;~(plug mixed-case-symbol ;~(pfix dot sym))
|
|
|
|
sym
|
|
|
|
==
|
|
|
|
++ parse-qualified-column ~+ (cook cook-qualified-column parse-column)
|
|
|
|
::
|
|
|
|
:: predicate
|
|
|
|
::
|
|
|
|
++ parse-operator ~+ ;~ pose
|
|
|
|
:: binary operators
|
|
|
|
(cold %eq (just '='))
|
|
|
|
(cold %neq ;~(pose (jest '<>') (jest '!=')))
|
|
|
|
(cold %gte ;~(pose (jest '>=') (jest '!<')))
|
|
|
|
(cold %lte ;~(pose (jest '<=') (jest '!>')))
|
|
|
|
(cold %gt (just '>'))
|
|
|
|
(cold %lt (just '<'))
|
|
|
|
(cold %and ;~(plug (jester 'and') whitespace))
|
|
|
|
(cold %or ;~(plug (jester 'or') whitespace))
|
|
|
|
(cold %equiv ;~(plug (jester 'equiv') whitespace))
|
|
|
|
(cold %not-equiv ;~(plug (jester 'not') whitespace (jester 'equiv') whitespace))
|
|
|
|
:: unary operators
|
|
|
|
(cold %not ;~(plug (jester 'not') whitespace))
|
|
|
|
(cold %exists ;~(plug (jester 'exists') whitespace))
|
|
|
|
(cold %in ;~(plug (jester 'in') whitespace))
|
|
|
|
(cold %any ;~(plug (jester 'any') whitespace))
|
|
|
|
(cold %all ;~(plug (jester 'all') whitespace))
|
|
|
|
:: ternary operator
|
|
|
|
(cold %between ;~(plug (jester 'between') whitespace))
|
|
|
|
:: nesting
|
|
|
|
(cold %pal pal)
|
|
|
|
(cold %par par)
|
2022-12-01 00:51:43 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
++ predicate-list
|
2023-03-16 23:49:28 +03:00
|
|
|
|= a=*
|
2023-05-02 20:33:46 +03:00
|
|
|
^- (list raw-predicate-component2)
|
|
|
|
=/ new-list=(list raw-predicate-component2) ~
|
2023-03-16 23:49:28 +03:00
|
|
|
|-
|
2023-05-02 20:33:46 +03:00
|
|
|
?: =(a ~) (flop new-list)
|
|
|
|
?: ?=(parens -.a) $(new-list [i=`parens`-.a t=new-list], a +.a)
|
|
|
|
?: ?=(ops-and-conjs:ast -.a) $(new-list [i=`ops-and-conjs:ast`-.a t=new-list], a +.a)
|
|
|
|
?: ?=(qualified-column:ast -.a) $(new-list [i=`qualified-column:ast`-.a t=new-list], a +.a)
|
2023-08-01 00:19:32 +03:00
|
|
|
?: ?=(dime -.a) $(new-list [i=`dime`-.a t=new-list], a +.a)
|
2023-05-02 20:33:46 +03:00
|
|
|
?: ?=(value-literal-list:ast -.a) $(new-list [i=`value-literal-list:ast`-.a t=new-list], a +.a)
|
|
|
|
?: ?&(=(%aggregate:ast -<.a) ?=(@ ->-.a) ?=(qualified-column:ast ->+.a))
|
|
|
|
$(new-list [i=(aggregate:ast %aggregate (aggregate-name ->-.a) `qualified-column:ast`->+.a) t=new-list], a +.a)
|
|
|
|
~|("problem with predicate noun: {<a>}" !!)
|
|
|
|
++ predicate-stop ~+ ;~ pose
|
|
|
|
;~(plug whitespace mic)
|
|
|
|
mic
|
|
|
|
;~(plug whitespace (jester 'where') whitespace)
|
|
|
|
;~(plug whitespace (jester 'when') whitespace)
|
|
|
|
;~(plug whitespace (jester 'select') whitespace)
|
|
|
|
;~(plug whitespace (jester 'as') whitespace)
|
|
|
|
;~(plug whitespace (jester 'join') whitespace)
|
|
|
|
;~(plug whitespace (jester 'left') whitespace)
|
|
|
|
;~(plug whitespace (jester 'right') whitespace)
|
|
|
|
;~(plug whitespace (jester 'outer') whitespace)
|
|
|
|
;~(plug whitespace (jester 'then') whitespace)
|
|
|
|
;~(plug whitespace (jester 'group') whitespace (jester 'by') whitespace)
|
|
|
|
==
|
|
|
|
++ predicate-part ~+ ;~ pose
|
|
|
|
parse-aggregate
|
|
|
|
value-literal-list
|
|
|
|
;~(pose ;~(pfix whitespace parse-operator) parse-operator)
|
|
|
|
parse-datum
|
|
|
|
==
|
|
|
|
++ parse-predicate
|
|
|
|
(star ;~(less predicate-stop predicate-part))
|
|
|
|
::
|
|
|
|
:: when not qualified by () right conjunction takes precedence and "or" takes precedence over "and"
|
|
|
|
::
|
|
|
|
:: 1=1 and 1=3 (false)
|
|
|
|
:: /\
|
|
|
|
:: 1=1 11=3
|
|
|
|
::
|
|
|
|
:: 1=1 and 1=3 and 1=4 (false)
|
|
|
|
:: /\
|
|
|
|
:: & 1=4
|
|
|
|
:: /\
|
|
|
|
:: 1=1 1=3
|
|
|
|
::
|
|
|
|
:: 1=2 and 3=3 and 1=4 or 1=1 (true)
|
|
|
|
:: /\
|
|
|
|
:: & 1=1
|
|
|
|
:: /\
|
|
|
|
:: & 1=4
|
|
|
|
:: /\
|
|
|
|
:: 1=1 3=3
|
|
|
|
::
|
|
|
|
:: 1=2 and 3=3 and 1=4 or 1=1 and 1=4 (false)
|
|
|
|
:: /\
|
|
|
|
:: & 1=1 and 1=4
|
|
|
|
:: /\
|
|
|
|
:: & 1=4
|
|
|
|
:: /\
|
|
|
|
:: 1=2 3=3
|
|
|
|
::
|
|
|
|
:: 1=2 and 3=3 and 1=4 or 1=1 and 1=4 or 2=2 (true)
|
|
|
|
:: /\
|
|
|
|
:: | 2=2
|
|
|
|
:: /\
|
|
|
|
:: & 1=1 and 1=4
|
|
|
|
:: /\
|
|
|
|
:: & 1=4
|
|
|
|
:: /\
|
|
|
|
:: 1=2 3=3
|
|
|
|
::
|
|
|
|
:: 1=2 and 3=3 and 1=4 or 1=1 and 1=4 or 2=2 and 3=2 (false)
|
|
|
|
:: /\
|
|
|
|
:: | 2=2 and 3=2
|
|
|
|
:: /\
|
|
|
|
:: & 1=1 and 1=4
|
|
|
|
:: /\
|
|
|
|
:: & 1=4
|
|
|
|
:: /\
|
|
|
|
:: 1=2 3=3
|
|
|
|
::
|
|
|
|
++ produce-predicate
|
|
|
|
|= parsed=(list raw-predicate-component2)
|
|
|
|
^- predicate:ast
|
|
|
|
=/ working-tree=predicate:ast ~
|
|
|
|
=/ tree-stack=(list predicate:ast) ~
|
2023-01-30 00:49:25 +03:00
|
|
|
|-
|
2023-05-02 20:33:46 +03:00
|
|
|
?: =((lent parsed) 0)
|
|
|
|
|-
|
|
|
|
?~ tree-stack
|
|
|
|
working-tree
|
|
|
|
%= $
|
|
|
|
working-tree
|
|
|
|
?~ ->-.tree-stack [-<.tree-stack working-tree ~]
|
|
|
|
[-<.tree-stack ->-.tree-stack working-tree]
|
|
|
|
tree-stack +.tree-stack
|
|
|
|
==
|
|
|
|
?- -.parsed
|
|
|
|
%pal :: push working predicate onto the stack
|
|
|
|
?~ working-tree $(parsed +.parsed)
|
|
|
|
%= $
|
|
|
|
tree-stack [working-tree tree-stack]
|
|
|
|
working-tree ~
|
|
|
|
parsed +.parsed
|
|
|
|
==
|
|
|
|
%par :: pop the stack, updating next working tree
|
|
|
|
?~ tree-stack $(parsed +.parsed)
|
|
|
|
%= $
|
|
|
|
tree-stack +.tree-stack
|
|
|
|
working-tree
|
|
|
|
?~ ->-.tree-stack [-<.tree-stack working-tree ~]
|
|
|
|
[-<.tree-stack ->-.tree-stack working-tree]
|
|
|
|
parsed +.parsed
|
|
|
|
==
|
2023-05-17 03:41:10 +03:00
|
|
|
unary-op:ast
|
2023-05-02 20:33:46 +03:00
|
|
|
?~ working-tree
|
|
|
|
%= $
|
|
|
|
working-tree [-.parsed ~ ~]
|
|
|
|
parsed +.parsed
|
|
|
|
==
|
|
|
|
?~ l.working-tree
|
|
|
|
?: ?&(=(%not -.working-tree) =(%exists -.parsed))
|
|
|
|
?> ?=(qualified-column:ast +<.parsed)
|
|
|
|
%= $
|
|
|
|
working-tree [-.working-tree [-.parsed [+<.parsed ~ ~] ~] ~]
|
|
|
|
parsed +>.parsed
|
|
|
|
==
|
|
|
|
~|("invalid compbination of unary operators {<-.working-tree>} and {<-.parsed>}" !!)
|
2023-05-17 03:41:10 +03:00
|
|
|
?~ r.working-tree ~|("unary-op, right tree empty {<working-tree>}" !!)
|
|
|
|
~|("unary-op can't get here {<working-tree>}" !!)
|
|
|
|
binary-op:ast
|
2023-05-02 20:33:46 +03:00
|
|
|
?~ working-tree !!
|
2023-05-17 03:41:10 +03:00
|
|
|
?~ l.working-tree ~|("binary-op, left tree empty {<working-tree>}" !!)
|
|
|
|
?~ r.working-tree ~|("binary-op, right tree empty {<working-tree>}" !!)
|
|
|
|
~|("binary-op can't get here {<working-tree>}" !!)
|
|
|
|
ternary-op:ast
|
2023-05-02 20:33:46 +03:00
|
|
|
?~ working-tree !!
|
2023-05-17 03:41:10 +03:00
|
|
|
?~ l.working-tree ~|("ternary-op, left tree empty {<working-tree>}" !!)
|
|
|
|
?~ r.working-tree ~|("ternary-op, right tree empty {<working-tree>}" !!)
|
|
|
|
~|("ternary-op can't get here {<working-tree>}" !!)
|
2023-05-02 20:33:46 +03:00
|
|
|
conjunction:ast
|
|
|
|
?~ working-tree
|
|
|
|
%= $
|
|
|
|
working-tree [-.parsed ~ ~]
|
|
|
|
parsed +.parsed
|
|
|
|
==
|
|
|
|
?~ l.working-tree ~|("conjunction, left tree empty {<working-tree>}" !!)
|
|
|
|
?~ r.working-tree ~|("conjunction, right tree empty {<working-tree>}" !!)
|
|
|
|
%= $
|
|
|
|
working-tree [-.parsed working-tree ~]
|
|
|
|
parsed +.parsed
|
|
|
|
==
|
2023-05-17 03:41:10 +03:00
|
|
|
all-any-op:ast
|
2023-05-02 20:33:46 +03:00
|
|
|
?~ working-tree ~|("operator {<-.parsed>} can only follow equality or inequality operator" !!)
|
|
|
|
?~ r.working-tree
|
2023-05-17 03:41:10 +03:00
|
|
|
?: ?&(?=(binary-op:ast n.working-tree) ?!(=(%in n.working-tree)))
|
2023-05-02 20:33:46 +03:00
|
|
|
?: ?=(value-literal-list:ast +<.parsed)
|
|
|
|
%= $
|
|
|
|
working-tree [-.working-tree +<.working-tree [-.parsed [+<.parsed ~ ~] ~]]
|
|
|
|
parsed +>.parsed
|
|
|
|
==
|
|
|
|
?: ?=(qualified-column:ast +<.parsed)
|
|
|
|
%= $
|
|
|
|
working-tree [-.working-tree +<.working-tree [-.parsed [+<.parsed ~ ~] ~]]
|
|
|
|
parsed +>.parsed
|
|
|
|
==
|
2023-05-17 03:41:10 +03:00
|
|
|
~|("all-any-op {<-.parsed>} must target CTE or literal list {<+<.parsed>}" !!)
|
|
|
|
~|("all-any-op {<-.parsed>} can only follow equality or inequality operator" !!)
|
|
|
|
~|("all-any-op {<-.parsed>} can't get here, working-tree {<working-tree>}" !!)
|
2023-05-02 20:33:46 +03:00
|
|
|
qualified-column:ast
|
|
|
|
?~ working-tree
|
2023-05-17 03:41:10 +03:00
|
|
|
?: ?=(binary-op:ast +<.parsed)
|
2023-05-02 20:33:46 +03:00
|
|
|
%= $
|
|
|
|
working-tree [+<.parsed [-.parsed ~ ~] ~]
|
|
|
|
parsed +>.parsed
|
|
|
|
==
|
2023-05-17 03:41:10 +03:00
|
|
|
?: ?=(unary-op:ast +<.parsed)
|
2023-05-02 20:33:46 +03:00
|
|
|
?: ?&(=(%not +<.parsed) =(%between +>-.parsed))
|
|
|
|
?: =(%and +>+>-.parsed)
|
|
|
|
%= $
|
|
|
|
working-tree
|
|
|
|
[%not [%between (produce-predicate ~[-.parsed %gte +>+<.parsed]) (produce-predicate ~[-.parsed %lte +>+>+<.parsed])] ~]
|
|
|
|
parsed +>+>+>.parsed
|
|
|
|
==
|
|
|
|
%= $
|
|
|
|
working-tree
|
|
|
|
[%not [%between (produce-predicate ~[-.parsed %gte +>+<.parsed]) (produce-predicate ~[-.parsed %lte +>+>-.parsed])] ~]
|
|
|
|
parsed +>+>+.parsed
|
|
|
|
==
|
|
|
|
?: =(%in +>-.parsed)
|
|
|
|
%= $
|
|
|
|
working-tree [%not (produce-predicate ~[-.parsed %in +>+<.parsed]) ~]
|
|
|
|
parsed +>+>.parsed
|
|
|
|
==
|
2023-05-17 03:41:10 +03:00
|
|
|
~|("unary-op {<+<.parsed>} can't get here after qualified-column, working-tree {<working-tree>}" !!)
|
2023-05-02 20:33:46 +03:00
|
|
|
?: =(%between +<.parsed)
|
|
|
|
?: =(%and +>+<.parsed)
|
|
|
|
%= $
|
|
|
|
working-tree
|
|
|
|
[%between (produce-predicate ~[-.parsed %gte +>-.parsed]) (produce-predicate ~[-.parsed %lte +>+>-.parsed])]
|
|
|
|
parsed +>+>+.parsed
|
|
|
|
==
|
|
|
|
%= $
|
|
|
|
working-tree
|
|
|
|
[%between (produce-predicate ~[-.parsed %gte +>-.parsed]) (produce-predicate ~[-.parsed %lte +>+<.parsed])]
|
|
|
|
parsed +>+>.parsed
|
|
|
|
==
|
|
|
|
~|("qualified-column can't get here after {<+<.parsed>} , working-tree {<working-tree>}" !!)
|
|
|
|
?~ l.working-tree
|
2023-01-30 00:49:25 +03:00
|
|
|
%= $
|
2023-05-02 20:33:46 +03:00
|
|
|
working-tree [-.working-tree [-.parsed ~ ~] ~]
|
|
|
|
parsed +.parsed
|
2023-01-30 00:49:25 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
?~ r.working-tree
|
|
|
|
?: ?=(conjunction:ast -.working-tree)
|
|
|
|
%= $
|
|
|
|
working-tree ~
|
|
|
|
tree-stack [working-tree tree-stack]
|
|
|
|
==
|
2023-01-30 00:49:25 +03:00
|
|
|
%= $
|
2023-05-02 20:33:46 +03:00
|
|
|
working-tree [-.working-tree +<.working-tree [-.parsed ~ ~]]
|
|
|
|
parsed +.parsed
|
2023-01-30 00:49:25 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
~|("qualified-column can't get here" !!)
|
2023-08-01 00:19:32 +03:00
|
|
|
dime
|
2023-05-02 20:33:46 +03:00
|
|
|
?~ working-tree
|
2023-05-17 03:41:10 +03:00
|
|
|
?: ?=(binary-op:ast +<.parsed)
|
2023-05-02 20:33:46 +03:00
|
|
|
%= $
|
|
|
|
working-tree [+<.parsed [-.parsed ~ ~] ~]
|
|
|
|
parsed +>.parsed
|
|
|
|
==
|
2023-05-17 03:41:10 +03:00
|
|
|
?: ?=(unary-op:ast +<.parsed)
|
2023-05-02 20:33:46 +03:00
|
|
|
?: ?&(=(%not +<.parsed) =(%between +>-.parsed))
|
|
|
|
?: =(%and +>+>-.parsed)
|
|
|
|
%= $
|
|
|
|
working-tree
|
|
|
|
[%not [%between (produce-predicate ~[-.parsed %gte +>+<.parsed]) (produce-predicate ~[-.parsed %lte +>+>+<.parsed])] ~]
|
|
|
|
parsed +>+>+>.parsed
|
|
|
|
==
|
|
|
|
%= $
|
|
|
|
working-tree
|
|
|
|
[%not [%between (produce-predicate ~[-.parsed %gte +>+<.parsed]) (produce-predicate ~[-.parsed %lte +>+>-.parsed])] ~]
|
|
|
|
parsed +>+>+.parsed
|
|
|
|
==
|
|
|
|
?: =(%in +>-.parsed)
|
|
|
|
%= $
|
|
|
|
working-tree [%not (produce-predicate ~[-.parsed %in +>+<.parsed]) ~]
|
|
|
|
parsed +>+>.parsed
|
|
|
|
==
|
2023-05-17 03:41:10 +03:00
|
|
|
~|("unary-op {<+<.parsed>} can't get here after value-literal, working-tree {<working-tree>}" !!)
|
2023-05-02 20:33:46 +03:00
|
|
|
?: =(%between +<.parsed)
|
|
|
|
?: =(%and +>+<.parsed)
|
|
|
|
%= $
|
|
|
|
working-tree
|
|
|
|
[%between (produce-predicate ~[-.parsed %gte +>-.parsed]) (produce-predicate ~[-.parsed %lte +>+>-.parsed])]
|
|
|
|
parsed +>+>+.parsed
|
|
|
|
==
|
|
|
|
%= $
|
|
|
|
working-tree
|
|
|
|
[%between (produce-predicate ~[-.parsed %gte +>-.parsed]) (produce-predicate ~[-.parsed %lte +>+<.parsed])]
|
|
|
|
parsed +>+>.parsed
|
|
|
|
==
|
|
|
|
~|("value-literal can't get here after {<+<.parsed>} , working-tree {<working-tree>}" !!)
|
|
|
|
?~ l.working-tree
|
2023-01-30 00:49:25 +03:00
|
|
|
%= $
|
2023-05-02 20:33:46 +03:00
|
|
|
working-tree [-.working-tree [-.parsed ~ ~] ~]
|
|
|
|
parsed +.parsed
|
2023-01-30 00:49:25 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
?~ r.working-tree
|
|
|
|
?: ?=(conjunction:ast -.working-tree)
|
|
|
|
%= $
|
|
|
|
working-tree ~
|
|
|
|
tree-stack [working-tree tree-stack]
|
|
|
|
==
|
|
|
|
%= $
|
|
|
|
working-tree [-.working-tree +<.working-tree [-.parsed ~ ~]]
|
|
|
|
parsed +.parsed
|
|
|
|
==
|
|
|
|
~|("value-literal can't get here" !!)
|
|
|
|
aggregate:ast
|
|
|
|
?~ working-tree
|
2023-05-17 03:41:10 +03:00
|
|
|
?: ?=(binary-op:ast +<.parsed)
|
2023-05-02 20:33:46 +03:00
|
|
|
%= $
|
|
|
|
working-tree [+<.parsed [-.parsed ~ ~] ~]
|
|
|
|
parsed +>.parsed
|
|
|
|
==
|
2023-05-17 03:41:10 +03:00
|
|
|
?: ?=(unary-op:ast +<.parsed)
|
2023-05-02 20:33:46 +03:00
|
|
|
?: ?&(=(%not +<.parsed) =(%between +>-.parsed))
|
|
|
|
?: =(%and +>+>-.parsed)
|
|
|
|
%= $
|
|
|
|
working-tree
|
|
|
|
[%not [%between (produce-predicate ~[-.parsed %gte +>+<.parsed]) (produce-predicate ~[-.parsed %lte +>+>+<.parsed])] ~]
|
|
|
|
parsed +>+>+>.parsed
|
|
|
|
==
|
|
|
|
%= $
|
|
|
|
working-tree
|
|
|
|
[%not [%between (produce-predicate ~[-.parsed %gte +>+<.parsed]) (produce-predicate ~[-.parsed %lte +>+>-.parsed])] ~]
|
|
|
|
parsed +>+>+.parsed
|
|
|
|
==
|
|
|
|
?: =(%in +>-.parsed)
|
|
|
|
%= $
|
|
|
|
working-tree [%not (produce-predicate ~[-.parsed %in +>+<.parsed]) ~]
|
|
|
|
parsed +>+>.parsed
|
|
|
|
==
|
2023-05-17 03:41:10 +03:00
|
|
|
~|("unary-op {<+<.parsed>} can't get here after aggregate, working-tree {<working-tree>}" !!)
|
2023-05-02 20:33:46 +03:00
|
|
|
?: =(%between +<.parsed)
|
|
|
|
?: =(%and +>+<.parsed)
|
|
|
|
%= $
|
|
|
|
working-tree
|
|
|
|
[%between (produce-predicate ~[-.parsed %gte +>-.parsed]) (produce-predicate ~[-.parsed %lte +>+>-.parsed])]
|
|
|
|
parsed +>+>+.parsed
|
|
|
|
==
|
|
|
|
%= $
|
|
|
|
working-tree
|
|
|
|
[%between (produce-predicate ~[-.parsed %gte +>-.parsed]) (produce-predicate ~[-.parsed %lte +>+<.parsed])]
|
|
|
|
parsed +>+>.parsed
|
|
|
|
==
|
|
|
|
~|("aggregate can't get here after {<+<.parsed>} , working-tree {<working-tree>}" !!)
|
|
|
|
?~ l.working-tree
|
|
|
|
%= $
|
|
|
|
working-tree [-.working-tree [-.parsed ~ ~] ~]
|
|
|
|
parsed +.parsed
|
|
|
|
==
|
|
|
|
?~ r.working-tree
|
|
|
|
?: ?=(conjunction:ast -.working-tree)
|
|
|
|
%= $
|
|
|
|
working-tree ~
|
|
|
|
tree-stack [working-tree tree-stack]
|
|
|
|
==
|
|
|
|
%= $
|
|
|
|
working-tree [-.working-tree +<.working-tree [-.parsed ~ ~]]
|
|
|
|
parsed +.parsed
|
|
|
|
==
|
|
|
|
~|("selected-aggregate can't get here" !!)
|
|
|
|
value-literal-list:ast
|
|
|
|
?~ working-tree ~|("Literal list in a predicate can only follow the IN operator" !!)
|
|
|
|
?~ l.working-tree !!
|
|
|
|
?~ r.working-tree
|
|
|
|
%= $
|
|
|
|
working-tree [-.working-tree +<.working-tree [-.parsed ~ ~]]
|
|
|
|
parsed +.parsed
|
|
|
|
==
|
|
|
|
~|("value-literal-list can't get here" !!)
|
2022-08-29 21:29:37 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
::
|
|
|
|
:: parse scalar
|
|
|
|
::
|
|
|
|
++ get-datum ~+ ;~ pose
|
|
|
|
;~(sfix parse-qualified-column whitespace)
|
|
|
|
;~(sfix parse-value-literal whitespace)
|
|
|
|
;~(sfix parse-datum whitespace)
|
|
|
|
parse-datum
|
2022-08-29 21:29:37 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
::++ cook-if
|
|
|
|
:: |= parsed=*
|
|
|
|
:: ^- if-then-else:ast
|
|
|
|
:: (if-then-else:ast %if-then-else -.parsed +>-.parsed +>+>-.parsed)
|
|
|
|
++ parse-if ;~ plug
|
|
|
|
parse-predicate
|
|
|
|
;~(pfix whitespace (cold %then (jester 'then')))
|
|
|
|
;~(pose scalar-body parse-datum)
|
|
|
|
;~(pfix whitespace (cold %else (jester 'else')))
|
|
|
|
;~(pose scalar-body parse-datum)
|
|
|
|
;~(pfix whitespace (cold %endif (jester 'endif')))
|
2022-09-12 22:38:25 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
++ parse-when-then ;~ plug
|
|
|
|
;~(pfix whitespace (cold %when (jester 'when')))
|
|
|
|
;~(pose parse-predicate parse-datum)
|
|
|
|
;~(pfix whitespace (cold %then (jester 'then')))
|
|
|
|
;~(pose parse-aggregate scalar-body parse-datum)
|
2023-02-15 01:22:54 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
++ parse-case-else ;~ plug
|
|
|
|
;~(pfix whitespace (cold %else (jester 'else')))
|
|
|
|
;~(pfix whitespace ;~(pose parse-aggregate scalar-body parse-datum))
|
|
|
|
;~(pfix whitespace (cold %end (jester 'end')))
|
2023-02-15 01:22:54 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
++ cook-case
|
|
|
|
|= parsed=*
|
|
|
|
~+
|
|
|
|
=/ raw-cases +<.parsed
|
|
|
|
=/ cases=(list case-when-then:ast) ~
|
|
|
|
|-
|
|
|
|
?. =(raw-cases ~)
|
|
|
|
$(cases [(case-when-then:ast ->-.raw-cases ->+>.raw-cases) cases], raw-cases +.raw-cases)
|
|
|
|
?: ?=(qualified-column:ast -.parsed)
|
|
|
|
?: =('else' +>-.parsed) (case:ast %case -.parsed (flop cases) +>+<.parsed)
|
|
|
|
(case:ast %case -.parsed (flop cases) ~)
|
2023-08-01 00:19:32 +03:00
|
|
|
?: ?=(dime -.parsed)
|
2023-05-02 20:33:46 +03:00
|
|
|
?: =('else' +>-.parsed) (case:ast %case -.parsed (flop cases) +>+<.parsed)
|
|
|
|
(case:ast %case -.parsed (flop cases) ~)
|
|
|
|
~|("cannot parse case {<parsed>}" !!)
|
|
|
|
++ parse-case ;~ plug
|
|
|
|
parse-datum
|
|
|
|
(star parse-when-then)
|
|
|
|
;~(pose parse-case-else ;~(pfix whitespace (cold %end (jester 'end'))))
|
2022-09-12 22:38:25 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
::++ cook-coalesce
|
|
|
|
:: |= parsed=(list datum:ast)
|
|
|
|
:: ^- coalesce:ast
|
|
|
|
:: (coalesce:ast %coalesce parsed)
|
|
|
|
++ scalar-token ;~ pose
|
|
|
|
;~(pfix whitespace (cold %end (jester 'end')))
|
|
|
|
;~(pfix whitespace ;~(plug (cold %if (jester 'if')) parse-if))
|
|
|
|
;~(plug (cold %if (jester 'if')) parse-if)
|
|
|
|
;~(pfix whitespace ;~(plug (cold %case (jester 'case')) parse-case))
|
|
|
|
;~(plug (cold %case (jester 'case')) parse-case)
|
|
|
|
;~(pfix whitespace ;~(plug (cold %coalesce (jester 'coalesce')) parse-coalesce))
|
|
|
|
;~(plug (cold %coalesce (jester 'coalesce')) parse-coalesce)
|
|
|
|
(cold %pal ;~(plug whitespace pal))
|
|
|
|
(cold %pal pal)
|
|
|
|
(cold %par ;~(plug whitespace par))
|
|
|
|
(cold %par par)
|
|
|
|
(cold %lus ;~(plug whitespace lus))
|
|
|
|
(cold %lus lus)
|
|
|
|
(cold %hep ;~(plug whitespace hep))
|
|
|
|
(cold %hep hep)
|
|
|
|
(cold %tar ;~(plug whitespace tar))
|
|
|
|
(cold %tar tar)
|
|
|
|
(cold %fas ;~(plug whitespace fas))
|
|
|
|
(cold %fas fas)
|
|
|
|
(cold %ket ;~(plug whitespace ket))
|
|
|
|
(cold %ket ket)
|
|
|
|
parse-datum
|
2023-01-11 02:26:55 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
++ parse-coalesce ~+ (more com ;~(pose parse-aggregate get-datum))
|
|
|
|
++ parse-math ;~ plug
|
|
|
|
(cold %begin (jester 'begin'))
|
|
|
|
(star scalar-token)
|
2023-02-04 03:23:51 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
++ parse-scalar-body %+ knee *noun
|
|
|
|
|. ~+
|
|
|
|
;~ pose
|
|
|
|
;~(plug (cold %if (jester 'if')) parse-if)
|
|
|
|
;~(plug (cold %case (jester 'case')) parse-case)
|
|
|
|
;~(plug (cold %coalesce (jester 'coalesce')) parse-coalesce)
|
|
|
|
parse-math
|
2023-02-15 01:22:54 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
++ scalar-stop ;~ pose
|
|
|
|
;~(plug whitespace (jester 'where'))
|
|
|
|
;~(plug whitespace (jester 'scalar'))
|
|
|
|
;~(plug whitespace (jester 'select'))
|
2023-02-15 01:22:54 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
++ scalar-body ;~(pfix whitespace parse-scalar-body)
|
|
|
|
++ parse-scalar-part ~+ ;~ plug
|
|
|
|
(cold %scalar ;~(pfix whitespace (jester 'scalar')))
|
|
|
|
parse-face
|
2023-02-06 02:27:50 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
++ parse-scalar ;~ pose
|
|
|
|
;~(plug parse-scalar-part ;~(pfix ;~(plug whitespace (jester 'as')) scalar-body))
|
|
|
|
;~(plug parse-scalar-part scalar-body)
|
2023-02-04 03:23:51 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
::
|
|
|
|
:: select
|
|
|
|
::
|
|
|
|
++ parse-alias-all (stag %all-columns ;~(sfix parse-alias ;~(plug dot tar)))
|
|
|
|
++ parse-object-all (stag %all-columns ;~(sfix parse-qualified-object ;~(plug dot tar)))
|
|
|
|
++ parse-selection ~+ ;~ pose
|
|
|
|
;~(plug ;~(sfix parse-selected-aggregate whitespace) (cold %as (jester 'as')) ;~(pfix whitespace alias))
|
|
|
|
parse-selected-aggregate
|
|
|
|
parse-alias-all
|
|
|
|
parse-object-all
|
|
|
|
;~(plug ;~(sfix ;~(pose parse-qualified-column parse-value-literal) whitespace) (cold %as (jester 'as')) ;~(pfix whitespace alias))
|
|
|
|
;~(pose parse-qualified-column parse-value-literal)
|
|
|
|
(cold %all tar)
|
2023-01-30 00:49:25 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
++ select-column ;~ pose
|
|
|
|
(ifix [whitespace whitespace] parse-selection)
|
|
|
|
;~(plug whitespace parse-selection)
|
|
|
|
parse-selection
|
2023-01-11 02:26:55 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
++ select-columns ;~ pose
|
|
|
|
(more com select-column)
|
|
|
|
select-column
|
2023-03-03 20:35:01 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
++ select-top-bottom ;~ plug
|
|
|
|
(cold %top ;~(plug whitespace (jester 'top')))
|
|
|
|
;~(pfix whitespace dem)
|
|
|
|
(cold %bottom ;~(plug whitespace (jester 'bottom')))
|
|
|
|
;~(pfix whitespace dem)
|
|
|
|
select-columns
|
2023-03-03 20:35:01 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
++ select-top ;~ plug
|
|
|
|
(cold %top ;~(plug whitespace (jester 'top')))
|
|
|
|
;~(pfix whitespace dem)
|
|
|
|
;~(less ;~(plug whitespace (jester 'bottom')) select-columns)
|
2023-04-12 21:20:04 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
++ select-bottom ;~ plug
|
|
|
|
(cold %bottom ;~(plug whitespace (jester 'bottom')))
|
|
|
|
;~(pfix whitespace dem)
|
|
|
|
select-columns
|
2023-04-12 21:20:04 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
++ parse-select ;~ plug
|
|
|
|
(cold %select ;~(plug whitespace (jester 'select')))
|
2023-04-12 21:20:04 +03:00
|
|
|
;~ pose
|
2023-05-02 20:33:46 +03:00
|
|
|
select-top-bottom
|
|
|
|
select-top
|
|
|
|
select-bottom
|
|
|
|
select-columns
|
2023-04-12 21:20:04 +03:00
|
|
|
==
|
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
::
|
|
|
|
:: group and order by
|
|
|
|
::
|
|
|
|
++ parse-grouping-column (ifix [whitespace whitespace] ;~(pose parse-qualified-column dem))
|
|
|
|
++ parse-group-by ;~ plug
|
|
|
|
(cold %group-by ;~(plug whitespace (jester 'group') whitespace (jester 'by')))
|
|
|
|
(more com parse-grouping-column)
|
2023-04-12 21:20:04 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
++ cook-ordering-column
|
|
|
|
|= parsed=*
|
|
|
|
?: ?=(qualified-column:ast parsed) (ordering-column:ast %ordering-column parsed %.y)
|
|
|
|
?@ parsed (ordering-column:ast %ordering-column parsed %.y)
|
|
|
|
?: =(+.parsed %asc) (ordering-column:ast %ordering-column -.parsed %.y)
|
|
|
|
(ordering-column:ast %ordering-column -.parsed %.n)
|
|
|
|
++ parse-ordered-column
|
|
|
|
(cook cook-ordering-column ;~(plug ;~(pose parse-qualified-column dem) ;~(pfix whitespace ;~(pose (cold %asc (jester 'asc')) (cold %desc (jester 'desc'))))))
|
|
|
|
++ parse-ordering-column ;~ pose
|
|
|
|
(ifix [whitespace whitespace] parse-ordered-column)
|
|
|
|
(cook cook-ordering-column (ifix [whitespace whitespace] ;~(pose parse-qualified-column dem)))
|
2023-04-12 21:20:04 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
++ parse-order-by ;~ plug
|
|
|
|
(cold %order-by ;~(plug whitespace (jester 'order') whitespace (jester 'by')))
|
|
|
|
(more com parse-ordering-column)
|
2023-03-16 23:49:28 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
++ make-query-object
|
|
|
|
|= a=*
|
2023-05-15 19:48:28 +03:00
|
|
|
^- table-set:ast
|
2023-05-17 03:34:14 +03:00
|
|
|
?: ?=(qualified-object:ast a)
|
|
|
|
(table-set:ast %table-set a ~)
|
2023-05-02 20:33:46 +03:00
|
|
|
?: ?=(qualified-object:ast -.a)
|
2023-05-15 19:48:28 +03:00
|
|
|
?~ +.a (table-set:ast %table-set -.a ~)
|
2023-05-02 20:33:46 +03:00
|
|
|
?: ?=((unit @t) +.a)
|
2023-05-15 19:48:28 +03:00
|
|
|
(table-set:ast %table-set -.a +.a)
|
|
|
|
(table-set:ast %table-set -.a `+.a)
|
2023-05-02 20:33:46 +03:00
|
|
|
?: ?=([@ @] a)
|
2023-05-15 19:48:28 +03:00
|
|
|
(table-set:ast %table-set (qualified-object:ast %qualified-object ~ 'UNKNOWN' 'COLUMN-OR-CTE' -.a) `+.a)
|
2023-05-02 20:33:46 +03:00
|
|
|
=/ columns=(list @t) ~
|
|
|
|
=/ b ?: ?=([%query-row * @] a) +<.a
|
|
|
|
?: =(%query-row -.a) +.a
|
|
|
|
?: =(%query-row -<.a) ->.a -.a
|
|
|
|
=/ alias ?: ?=([%query-row * @] a) +>.a
|
|
|
|
?: =(%query-row -.a) ~ +.a
|
|
|
|
|-
|
|
|
|
?~ b
|
2023-05-15 19:48:28 +03:00
|
|
|
?~ alias (table-set:ast %table-set object=(query-row:ast %query-row (flop columns)) ~)
|
|
|
|
(table-set:ast %table-set object=(query-row:ast %query-row (flop columns)) `alias)
|
2023-05-02 20:33:46 +03:00
|
|
|
?@ -.b $(b +.b, columns [-.b columns])
|
|
|
|
~|("cannot make-query-object: {<a>}" !!)
|
|
|
|
++ produce-from
|
2023-03-16 23:49:28 +03:00
|
|
|
|= a=*
|
2023-05-02 20:33:46 +03:00
|
|
|
^- from:ast
|
2023-05-15 19:48:28 +03:00
|
|
|
=/ query-object=table-set:ast (make-query-object ->.a)
|
2023-05-02 20:33:46 +03:00
|
|
|
=/ raw-joined-objects +.a
|
|
|
|
=/ joined-objects=(list joined-object:ast) ~
|
|
|
|
=/ is-cross-join=? %.n
|
2023-03-16 23:49:28 +03:00
|
|
|
|-
|
2023-05-02 20:33:46 +03:00
|
|
|
?: =(raw-joined-objects ~)
|
|
|
|
?: is-cross-join
|
|
|
|
?: =((lent joined-objects) 1)
|
|
|
|
(from:ast %from query-object (flop joined-objects))
|
|
|
|
~|("cross join must be only join in query" !!)
|
|
|
|
(from:ast %from query-object (flop joined-objects))
|
|
|
|
?: ?=(%cross-join -.raw-joined-objects)
|
2023-03-16 23:49:28 +03:00
|
|
|
%= $
|
2023-05-02 20:33:46 +03:00
|
|
|
joined-objects
|
|
|
|
[(joined-object:ast %joined-object %cross-join (make-query-object +>.raw-joined-objects) ~) joined-objects]
|
|
|
|
is-cross-join %.y
|
|
|
|
raw-joined-objects ~
|
2023-03-16 23:49:28 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
?> ?=(join-type:ast -<.raw-joined-objects)
|
|
|
|
=/ joined=joined-object:ast
|
|
|
|
(joined-object:ast %joined-object -<.raw-joined-objects (make-query-object ->->.raw-joined-objects) `(produce-predicate (predicate-list ->+.raw-joined-objects)))
|
|
|
|
%= $
|
|
|
|
joined-objects [joined joined-objects]
|
|
|
|
raw-joined-objects +.raw-joined-objects
|
2023-03-16 23:49:28 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
++ produce-ctes
|
|
|
|
|= a=*
|
2023-05-15 19:48:28 +03:00
|
|
|
^- (list cte:ast)
|
|
|
|
=/ ctes=(list cte:ast) ~
|
2023-05-02 20:33:46 +03:00
|
|
|
|-
|
|
|
|
?~ a (flop ctes)
|
|
|
|
?: ?&(=(%cte -<.a) =(%as ->+<.a))
|
|
|
|
%= $
|
|
|
|
a +.a
|
2023-05-15 19:48:28 +03:00
|
|
|
ctes [(cte:ast %cte ->+>.a (produce-query ->-.a)) ctes]
|
2022-08-29 21:29:37 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
~|('cannot produce ctes from parsed: {<a>}' !!)
|
|
|
|
++ produce-delete
|
|
|
|
|= a=*
|
|
|
|
^- delete:ast
|
|
|
|
?> ?=(qualified-object:ast -.a)
|
|
|
|
?: =(%end-command +<.a)
|
2023-05-16 22:59:29 +03:00
|
|
|
(delete:ast %delete -.a ~)
|
2023-05-02 20:33:46 +03:00
|
|
|
?: =(%where +<.a)
|
2023-05-15 19:48:28 +03:00
|
|
|
(delete:ast %delete -.a `(produce-predicate (predicate-list +>-.a)))
|
|
|
|
(delete:ast %delete -.a `(produce-predicate (predicate-list +>->.a)))
|
2023-05-02 20:33:46 +03:00
|
|
|
++ produce-select
|
|
|
|
|= a=*
|
|
|
|
^- select:ast
|
|
|
|
=/ top=(unit @ud) ~
|
|
|
|
=/ bottom=(unit @ud) ~
|
|
|
|
=/ columns=(list selected-column:ast) ~
|
2022-08-06 17:06:18 +03:00
|
|
|
|-
|
2023-05-02 20:33:46 +03:00
|
|
|
~| "cannot parse select -.a: {<-.a>}"
|
|
|
|
?~ a
|
|
|
|
?~ columns ~|('no columns selected' !!)
|
2023-05-31 01:43:53 +03:00
|
|
|
(select:ast %select top bottom (flop columns))
|
2023-05-02 20:33:46 +03:00
|
|
|
?@ -.a
|
|
|
|
?+ -.a ~|('some other select atom' !!)
|
|
|
|
%top ?> ?=(@ud +<.a) $(top `+<.a, a +>.a)
|
|
|
|
%bottom ?> ?=(@ud +<.a) $(bottom `+<.a, a +>.a)
|
|
|
|
%all
|
2022-12-01 00:51:43 +03:00
|
|
|
%= $
|
2023-05-02 20:33:46 +03:00
|
|
|
columns [(qualified-object:ast %qualified-object ~ 'ALL' 'ALL' 'ALL') columns]
|
|
|
|
a +.a
|
2022-12-01 00:51:43 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
|
|
|
?: ?=([[%selected-aggregate @ %qualified-column [%qualified-object @ @ @ @] @ @] %as @] -.a)
|
2022-12-01 00:51:43 +03:00
|
|
|
%= $
|
2023-05-02 20:33:46 +03:00
|
|
|
columns [(selected-aggregate:ast %selected-aggregate (aggregate:ast %aggregate (aggregate-name -<+<.a) (qualified-column:ast %qualified-column -<+>+<.a -<+>+>-.a -<+>+>+.a)) `->+.a) columns]
|
|
|
|
a +.a
|
2022-09-07 23:50:04 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
?: ?=([%selected-aggregate @ %qualified-column [%qualified-object @ @ @ @] @ @] -.a)
|
2022-12-01 00:51:43 +03:00
|
|
|
%= $
|
2023-05-02 20:33:46 +03:00
|
|
|
columns [(selected-aggregate:ast %selected-aggregate (aggregate:ast %aggregate (aggregate-name ->-.a) (qualified-column:ast %qualified-column ->+>-.a ->+>+<.a ->+>+>.a)) ~) columns]
|
|
|
|
a +.a
|
2022-08-14 00:20:30 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
?: ?=([%all-columns %qualified-object @ @ @ @] -.a)
|
|
|
|
%= $
|
|
|
|
columns [(qualified-column:ast %qualified-column (qualified-object:ast %qualified-object ->+<.a ->+>-.a ->+>+<.a ->+>+>.a) 'ALL' ~) columns]
|
|
|
|
a +.a
|
|
|
|
==
|
|
|
|
?: ?=([@ @] -.a)
|
|
|
|
?: =(%all-columns -<.a)
|
2022-12-01 00:51:43 +03:00
|
|
|
%= $
|
2023-05-02 20:33:46 +03:00
|
|
|
columns [(qualified-column:ast %qualified-column (qualified-object:ast %qualified-object ~ 'UNKNOWN' 'COLUMN-OR-CTE' ->.a) 'ALL' ~) columns]
|
|
|
|
a +.a
|
2022-08-29 21:29:37 +03:00
|
|
|
==
|
2023-08-01 00:19:32 +03:00
|
|
|
?> ?=(dime -.a)
|
2022-12-01 00:51:43 +03:00
|
|
|
%= $
|
2023-05-02 20:33:46 +03:00
|
|
|
columns [(selected-value:ast %selected-value -.a ~) columns]
|
|
|
|
a +.a
|
2022-08-13 05:00:44 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
?: ?=([qualified-column:ast %as @] -.a)
|
2022-12-01 00:51:43 +03:00
|
|
|
%= $
|
2023-05-02 20:33:46 +03:00
|
|
|
columns [(qualified-column:ast %qualified-column (qualified-object:ast %qualified-object -<+<+<.a -<+<+>-.a -<+<+>+<.a -<+<+>+>.a) -<+>-.a `->+.a) columns]
|
|
|
|
a +.a
|
2022-08-13 05:00:44 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
?: ?=([[@tas @] %as @] -.a)
|
2022-09-02 03:14:57 +03:00
|
|
|
%= $
|
2023-08-08 22:16:55 +03:00
|
|
|
columns [(selected-value:ast %selected-value -<.a `(crip (cass (trip ->+.a)))) columns]
|
2023-05-02 20:33:46 +03:00
|
|
|
a +.a
|
|
|
|
==
|
|
|
|
?> ?=(qualified-column:ast -.a) $(columns [-.a columns], a +.a)
|
2023-05-15 17:39:13 +03:00
|
|
|
++ produce-query
|
2023-05-02 20:33:46 +03:00
|
|
|
|= a=*
|
2023-05-15 17:39:13 +03:00
|
|
|
^- query:ast
|
2023-05-02 20:33:46 +03:00
|
|
|
=/ from=(unit from:ast) ~
|
|
|
|
=/ scalars=(list scalar-function:ast) ~
|
|
|
|
=/ predicate=(unit predicate:ast) ~
|
|
|
|
=/ group-by=(list grouping-column:ast) ~
|
|
|
|
=/ having=(unit predicate:ast) ~
|
|
|
|
=/ select=(unit select:ast) ~
|
|
|
|
=/ order-by=(list ordering-column:ast) ~
|
|
|
|
|-
|
2023-05-15 17:39:13 +03:00
|
|
|
?~ a ~|("cannot parse query {<a>}" !!)
|
2023-05-02 20:33:46 +03:00
|
|
|
?: =(-.a %query) $(a +.a)
|
|
|
|
?: =(-.a %end-command)
|
2023-05-15 17:39:13 +03:00
|
|
|
(query:ast %query from scalars predicate group-by having (need select) order-by)
|
2023-05-02 20:33:46 +03:00
|
|
|
::?: =(i.a %scalars) $(a t.a, scalars +.i.a)
|
|
|
|
?: =(-<.a %scalars) $(a +.a, scalars ~)
|
|
|
|
?: =(-<.a %where) $(a +.a, predicate `(produce-predicate (predicate-list ->.a)))
|
|
|
|
?: =(-<.a %select) $(a +.a, select `(produce-select ->.a))
|
|
|
|
?: =(-<.a %group-by) $(a +.a, group-by (group-by-list ->.a))
|
|
|
|
?: =(-<.a %order-by) $(a +.a, order-by (order-by-list ->.a))
|
2023-05-15 19:48:28 +03:00
|
|
|
?: =(-<-.a %table-set) $(a +.a, from `(produce-from -.a))
|
2023-05-02 20:33:46 +03:00
|
|
|
?: =(-<-.a %query-row) $(a +.a, from `(produce-from -.a))
|
2023-05-15 17:39:13 +03:00
|
|
|
~|("cannot parse query {<a>}" !!)
|
2023-05-02 20:33:46 +03:00
|
|
|
::
|
|
|
|
:: parse urQL command
|
|
|
|
::
|
|
|
|
++ parse-alter-index
|
|
|
|
=/ columns ;~(pfix whitespace ordered-column-list)
|
|
|
|
=/ action ;~(pfix whitespace ;~(pose (jester 'rebuild') (jester 'disable') (jester 'resume')))
|
|
|
|
;~ plug
|
|
|
|
;~(pfix whitespace parse-qualified-3object)
|
|
|
|
;~(pfix whitespace ;~(pfix (jester 'on') ;~(pfix whitespace parse-qualified-3object)))
|
|
|
|
;~(sfix ;~(pose ;~(plug columns action) columns action) end-or-next-command)
|
|
|
|
==
|
|
|
|
++ parse-alter-namespace ;~ plug
|
2023-08-01 00:19:32 +03:00
|
|
|
(cook |=(a=* (qualified-namespace [a default-database])) parse-qualified-2-name)
|
2023-05-02 20:33:46 +03:00
|
|
|
;~(pfix ;~(plug whitespace (jester 'transfer')) ;~(pfix whitespace ;~(pose (jester 'table') (jester 'view'))))
|
|
|
|
;~(sfix ;~(pfix whitespace parse-qualified-3object) end-or-next-command)
|
|
|
|
==
|
|
|
|
++ parse-alter-table ;~ plug
|
|
|
|
;~(pfix whitespace parse-qualified-3object)
|
|
|
|
;~(sfix ;~(pfix whitespace ;~(pose alter-columns add-columns drop-columns add-foreign-key drop-foreign-key)) end-or-next-command)
|
|
|
|
==
|
|
|
|
++ parse-create-namespace ;~ sfix
|
|
|
|
parse-qualified-2-name
|
|
|
|
end-or-next-command
|
|
|
|
==
|
|
|
|
++ parse-create-index
|
2023-08-01 00:19:32 +03:00
|
|
|
=/ unique ;~(pfix whitespace (jester 'unique'))
|
2023-05-02 21:21:45 +03:00
|
|
|
=/ index-name ;~(pfix whitespace (jester 'index') parse-face)
|
2023-05-02 20:33:46 +03:00
|
|
|
=/ type-and-name ;~ pose
|
2023-08-01 00:19:32 +03:00
|
|
|
;~(plug unique clustering index-name)
|
|
|
|
;~(plug unique index-name)
|
2023-05-02 20:33:46 +03:00
|
|
|
;~(plug clustering index-name)
|
|
|
|
index-name
|
|
|
|
==
|
|
|
|
;~ plug
|
|
|
|
type-and-name
|
|
|
|
;~(pfix whitespace ;~(pfix (jester 'on') ;~(pfix whitespace parse-qualified-3object)))
|
|
|
|
;~(sfix ordered-column-list end-or-next-command)
|
|
|
|
==
|
|
|
|
++ parse-create-table ;~ plug
|
|
|
|
;~(pfix whitespace parse-qualified-3object)
|
|
|
|
column-definitions
|
|
|
|
;~(sfix ;~(pose ;~(plug primary-key ;~(pfix foreign-key-literal (more com full-foreign-key))) primary-key) end-or-next-command)
|
|
|
|
==
|
|
|
|
++ parse-drop-database ;~ sfix
|
|
|
|
;~(pose ;~(plug ;~(pfix whitespace (jester 'force')) ;~(pfix whitespace sym)) ;~(pfix whitespace sym))
|
|
|
|
end-or-next-command
|
|
|
|
==
|
|
|
|
++ parse-drop-index ;~ sfix
|
|
|
|
;~(pfix whitespace ;~(plug parse-face ;~(pfix whitespace ;~(pfix (jester 'on') ;~(pfix whitespace parse-qualified-3object)))))
|
|
|
|
end-or-next-command
|
|
|
|
==
|
|
|
|
++ parse-drop-namespace ;~ sfix
|
|
|
|
;~(pose ;~(plug ;~(pfix whitespace (cold %force (jester 'force'))) parse-qualified-2-name) parse-qualified-2-name)
|
|
|
|
end-or-next-command
|
|
|
|
==
|
|
|
|
++ drop-table-or-view ;~ sfix
|
|
|
|
;~(pose ;~(pfix whitespace ;~(plug (jester 'force') parse-qualified-3object)) parse-qualified-3object)
|
|
|
|
end-or-next-command
|
|
|
|
==
|
|
|
|
++ parse-grant ;~ plug
|
|
|
|
:: permission
|
|
|
|
;~(pfix whitespace ;~(pose (jester 'adminread') (jester 'readonly') (jester 'readwrite')))
|
|
|
|
:: grantee
|
|
|
|
;~(pfix whitespace ;~(pfix (jester 'to') ;~(pfix whitespace ;~(pose (jester 'parent') (jester 'siblings') (jester 'moons') (stag %ships ship-list)))))
|
|
|
|
;~(sfix grant-object end-or-next-command)
|
|
|
|
==
|
|
|
|
++ parse-insert ;~ plug
|
|
|
|
;~(pfix whitespace parse-qualified-object)
|
|
|
|
;~(pose ;~(plug face-list ;~(pfix whitespace (jester 'values'))) ;~(pfix whitespace (jester 'values')))
|
|
|
|
;~(pfix whitespace (more whitespace (ifix [pal par] (more com parse-insert-value))))
|
|
|
|
end-or-next-command
|
|
|
|
==
|
|
|
|
++ parse-query01 ;~ plug
|
|
|
|
parse-object-and-joins
|
|
|
|
:: (stag %scalars (star parse-scalar))
|
|
|
|
;~(pfix whitespace ;~(plug (cold %where (jester 'where')) parse-predicate))
|
|
|
|
parse-group-by
|
|
|
|
parse-select
|
|
|
|
parse-order-by
|
|
|
|
end-or-next-command
|
|
|
|
==
|
|
|
|
++ parse-query02 ;~ plug
|
|
|
|
parse-object-and-joins
|
|
|
|
:: (stag %scalars (star parse-scalar))
|
|
|
|
;~(pfix whitespace ;~(plug (cold %where (jester 'where')) parse-predicate))
|
|
|
|
parse-group-by
|
|
|
|
parse-select
|
|
|
|
end-or-next-command
|
|
|
|
==
|
|
|
|
++ parse-query03 ;~ plug
|
|
|
|
parse-object-and-joins
|
|
|
|
:: (stag %scalars (star parse-scalar))
|
|
|
|
;~(pfix whitespace ;~(plug (cold %where (jester 'where')) parse-predicate))
|
|
|
|
parse-select
|
|
|
|
parse-order-by
|
|
|
|
end-or-next-command
|
|
|
|
==
|
|
|
|
++ parse-query04 ;~ plug
|
|
|
|
parse-object-and-joins
|
|
|
|
:: (stag %scalars (star parse-scalar))
|
|
|
|
;~(pfix whitespace ;~(plug (cold %where (jester 'where')) parse-predicate))
|
|
|
|
parse-select
|
|
|
|
end-or-next-command
|
|
|
|
==
|
|
|
|
++ parse-query05 ;~ plug
|
|
|
|
parse-object-and-joins
|
|
|
|
:: (stag %scalars (star parse-scalar))
|
|
|
|
parse-select
|
|
|
|
parse-order-by
|
|
|
|
end-or-next-command
|
|
|
|
==
|
|
|
|
++ parse-query06 ;~ plug
|
|
|
|
parse-object-and-joins
|
|
|
|
:: (stag %scalars (star parse-scalar))
|
|
|
|
parse-select
|
|
|
|
end-or-next-command
|
|
|
|
==
|
|
|
|
++ parse-query07 ;~ plug
|
|
|
|
parse-object-and-joins
|
|
|
|
:: (stag %scalars (star parse-scalar))
|
|
|
|
parse-group-by
|
|
|
|
parse-select
|
|
|
|
parse-order-by
|
|
|
|
end-or-next-command
|
|
|
|
==
|
|
|
|
++ parse-query08 ;~ plug
|
|
|
|
parse-object-and-joins
|
|
|
|
:: (stag %scalars (star parse-scalar))
|
|
|
|
parse-group-by
|
|
|
|
parse-select
|
|
|
|
end-or-next-command
|
|
|
|
==
|
|
|
|
++ parse-query09 ;~ plug
|
|
|
|
parse-object-and-joins
|
|
|
|
parse-select
|
|
|
|
end-or-next-command
|
|
|
|
==
|
|
|
|
++ parse-query10 ;~ plug
|
|
|
|
parse-select
|
|
|
|
end-or-next-command
|
|
|
|
==
|
|
|
|
++ parse-query ;~ pose
|
|
|
|
parse-query01
|
|
|
|
parse-query02
|
|
|
|
parse-query03
|
|
|
|
parse-query04
|
|
|
|
parse-query05
|
|
|
|
parse-query06
|
|
|
|
parse-query07
|
|
|
|
parse-query08
|
|
|
|
parse-query09
|
|
|
|
parse-query10
|
|
|
|
==
|
|
|
|
++ parse-cte ;~ plug
|
|
|
|
(cold %cte ;~(plug whitespace (jest '(')))
|
|
|
|
;~ pose
|
|
|
|
;~(pfix ;~(whitespace (jester 'from')) parse-query)
|
|
|
|
;~(pfix (jester 'from') parse-query)
|
|
|
|
parse-query
|
|
|
|
==
|
|
|
|
;~ pose
|
|
|
|
;~(pfix whitespace ;~(pfix (jest ')') ;~(pfix whitespace (jester 'as'))))
|
|
|
|
;~(pfix (jest ')') ;~(pfix whitespace (jester 'as')))
|
|
|
|
==
|
|
|
|
;~(pose ;~(sfix parse-alias whitespace) parse-alias)
|
|
|
|
==
|
|
|
|
++ parse-ctes
|
2023-05-16 22:59:29 +03:00
|
|
|
(more com ;~(pose with-stop parse-cte))
|
2023-05-02 20:33:46 +03:00
|
|
|
++ parse-delete ;~ plug
|
|
|
|
;~(pfix whitespace parse-qualified-3object)
|
|
|
|
;~ pose
|
|
|
|
;~(pfix whitespace ;~(plug (cold %where (jester 'where')) parse-predicate end-or-next-command))
|
|
|
|
end-or-next-command
|
|
|
|
==
|
|
|
|
==
|
|
|
|
++ merge-stop ;~ pose
|
|
|
|
;~(plug (jester 'with') whitespace)
|
|
|
|
;~(plug (jester 'using') whitespace)
|
|
|
|
;~(plug (jester 'on') whitespace)
|
|
|
|
;~(plug (jester 'when') whitespace)
|
|
|
|
==
|
|
|
|
++ parse-matching-predicate ;~ plug
|
|
|
|
(cold %predicate ;~(plug whitespace (jester 'and')))
|
|
|
|
parse-predicate
|
|
|
|
==
|
|
|
|
++ parse-merge-when ;~ plug
|
|
|
|
;~ pose
|
|
|
|
;~(plug (cold %matched ;~(plug (jester 'when') whitespace (jester 'matched'))) parse-matching-predicate)
|
|
|
|
(cold %matched ;~(plug (jester 'when') whitespace (jester 'matched')))
|
|
|
|
::
|
|
|
|
;~(plug (cold %unmatch-target ;~(plug (jester 'when') whitespace (jester 'not') whitespace (jester 'matched') whitespace (jester 'by') whitespace (jester 'target'))) parse-matching-predicate)
|
|
|
|
(cold %unmatch-target ;~(plug (jester 'when') whitespace (jester 'not') whitespace (jester 'matched') whitespace (jester 'by') whitespace (jester 'target')))
|
|
|
|
;~(plug (cold %unmatch-target ;~(plug (jester 'when') whitespace (jester 'not') whitespace (jester 'matched'))) parse-matching-predicate)
|
|
|
|
(cold %unmatch-target ;~(plug (jester 'when') whitespace (jester 'not') whitespace (jester 'matched')))
|
|
|
|
::
|
|
|
|
;~(plug (cold %unmatch-source ;~(plug (jester 'when') whitespace (jester 'not') whitespace (jester 'matched') whitespace (jester 'by') whitespace (jester 'source'))) parse-matching-predicate)
|
|
|
|
(cold %unmatch-source ;~(plug (jester 'when') whitespace (jester 'not') whitespace (jester 'matched') whitespace (jester 'by') whitespace (jester 'source')))
|
|
|
|
==
|
|
|
|
;~ pose
|
|
|
|
;~ plug
|
|
|
|
(cold %update ;~(pose ;~(plug whitespace (jester 'then') whitespace (jester 'update') whitespace (jester 'set')) ;~(plug whitespace (jester 'then') whitespace (jester 'update'))))
|
|
|
|
(more com update-column)
|
|
|
|
==
|
|
|
|
;~ plug
|
|
|
|
(cold %insert ;~(pose ;~(plug whitespace (jester 'then') whitespace (jester 'insert'))))
|
|
|
|
;~(pose ;~(plug face-list ;~(pfix whitespace (jester 'values'))) ;~(pfix whitespace (jester 'values')))
|
|
|
|
;~(pfix whitespace (more whitespace (ifix [pal par] (more com ;~(pose parse-qualified-column parse-insert-value)))))
|
|
|
|
==
|
|
|
|
==
|
|
|
|
==
|
|
|
|
++ parse-merge ;~ plug
|
|
|
|
;~ pose
|
|
|
|
;~(pfix whitespace ;~(plug parse-qualified-object ;~(pfix whitespace ;~(pfix (jester 'as') parse-alias))))
|
|
|
|
;~(pfix whitespace ;~(plug (stag %query-row face-list) ;~(pfix whitespace ;~(pfix (jester 'as') parse-alias))))
|
|
|
|
;~(pfix whitespace ;~(plug parse-qualified-object (cold %as whitespace) ;~(less merge-stop parse-alias)))
|
|
|
|
;~(pfix whitespace ;~(plug (stag %query-row face-list) ;~(pfix whitespace ;~(less merge-stop parse-alias))))
|
|
|
|
;~(pfix whitespace parse-qualified-object)
|
|
|
|
;~(pfix whitespace (stag %query-row face-list))
|
|
|
|
==
|
|
|
|
;~ pose
|
|
|
|
;~(plug (cold %using ;~(plug whitespace (jester 'using') whitespace)) ;~(plug ;~(pose parse-qualified-object parse-alias) ;~(pfix whitespace ;~(pfix (jester 'as') parse-alias))))
|
|
|
|
;~(plug (cold %using ;~(plug whitespace (jester 'using') whitespace)) (stag %query-row ;~(plug face-list ;~(pfix whitespace ;~(pfix (jester 'as') parse-alias)))))
|
|
|
|
;~(plug (cold %using ;~(plug whitespace (jester 'using') whitespace)) ;~(plug ;~(pose parse-qualified-object parse-alias) (cold %as whitespace) ;~(less merge-stop parse-alias)))
|
|
|
|
;~(plug (cold %using ;~(plug whitespace (jester 'using') whitespace)) (stag %query-row ;~(plug face-list ;~(pfix whitespace ;~(less merge-stop parse-alias)))))
|
|
|
|
;~(plug (cold %using ;~(plug whitespace (jester 'using') whitespace)) parse-qualified-object)
|
|
|
|
;~(plug (cold %using ;~(plug whitespace (jester 'using') whitespace)) (stag %query-row face-list))
|
|
|
|
==
|
|
|
|
;~(plug ;~(pfix whitespace (jester 'on')) parse-predicate)
|
|
|
|
;~(pfix whitespace (star parse-merge-when))
|
|
|
|
(easy ~)
|
|
|
|
==
|
2023-05-17 03:34:14 +03:00
|
|
|
++ produce-insert
|
|
|
|
|= a=*
|
|
|
|
^- insert:ast
|
|
|
|
?: ?=([[@ @ @ @ @] @ *] a) ::"insert rows"
|
|
|
|
(insert:ast %insert -.a ~ (insert-values:ast %data +>-.a))
|
|
|
|
?: ?=([[@ @ @ @ @] [* @] *] a) ::"insert column names rows"
|
|
|
|
(insert:ast %insert -.a `+<-.a (insert-values:ast %data +>-.a))
|
|
|
|
~|("Cannot parse insert {<a>}" !!)
|
2023-05-02 20:33:46 +03:00
|
|
|
++ produce-merge
|
|
|
|
|= a=*
|
|
|
|
^- merge:ast
|
|
|
|
=/ into=? %.y
|
2023-05-15 19:48:28 +03:00
|
|
|
=/ target-table=(unit table-set:ast) ~
|
|
|
|
=/ new-table=(unit table-set:ast) ~
|
|
|
|
=/ source-table=(unit table-set:ast) ~
|
2023-05-02 20:33:46 +03:00
|
|
|
=/ predicate=(unit predicate:ast) ~
|
|
|
|
=/ matching=[matched=(list matching:ast) not-target=(list matching:ast) not-source=(list matching:ast)] [~ ~ ~]
|
|
|
|
|-
|
|
|
|
?~ a ?: ?&(=(target-table ~) =(source-table ~)) ~|("target and source tables cannot both be pass through" !!)
|
2023-05-15 19:48:28 +03:00
|
|
|
(merge:ast %merge (need target-table) new-table (need source-table) (need predicate) matched=matched.matching unmatched-by-target=not-target.matching unmatched-by-source=not-source.matching)
|
2023-05-02 20:33:46 +03:00
|
|
|
?: ?=(qualified-object:ast -.a)
|
|
|
|
%= $
|
|
|
|
a +.a
|
2023-05-15 19:48:28 +03:00
|
|
|
target-table `(table-set:ast %table-set -.a ~)
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
|
|
|
?: ?=([%using @ %as @] -.a)
|
|
|
|
%= $
|
|
|
|
a +.a
|
2023-08-01 00:19:32 +03:00
|
|
|
source-table `(table-set:ast %table-set (qualified-object:ast %qualified-object ~ default-database 'dbo' +<.a) `+>+.a)
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
|
|
|
?: ?=([qualified-object:ast @] -.a)
|
|
|
|
%= $
|
|
|
|
a +.a
|
2023-05-17 03:34:14 +03:00
|
|
|
target-table `(make-query-object -.a)
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
|
|
|
?: ?=([%using qualified-object:ast %as @] -.a)
|
|
|
|
%= $
|
|
|
|
a +.a
|
2023-05-15 19:48:28 +03:00
|
|
|
source-table `(table-set:ast %table-set ->-.a `->+>.a)
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
|
|
|
?: =(%on -<.a)
|
|
|
|
%= $
|
|
|
|
a +.a
|
|
|
|
predicate `(produce-predicate (predicate-list ->.a))
|
|
|
|
==
|
|
|
|
?: =(%query-row -<.a)
|
|
|
|
%= $
|
|
|
|
a +.a
|
|
|
|
target-table `(make-query-object -.a)
|
|
|
|
==
|
|
|
|
?: =(%using -<.a)
|
|
|
|
%= $
|
|
|
|
a +.a
|
|
|
|
source-table `(make-query-object ->.a)
|
|
|
|
==
|
|
|
|
?: =(%query-row -<-.a)
|
|
|
|
%= $
|
|
|
|
a +.a
|
|
|
|
target-table `(make-query-object -.a)
|
|
|
|
==
|
|
|
|
%= $
|
|
|
|
a +.a
|
|
|
|
matching (produce-matching -.a)
|
|
|
|
==
|
|
|
|
++ produce-matching-profile
|
|
|
|
|= a=*
|
|
|
|
^- (list [@t datum:ast])
|
|
|
|
=/ profile=(list [@t datum:ast]) ~
|
|
|
|
|-
|
|
|
|
?~ a (flop profile)
|
|
|
|
?: ?=([@ %qualified-column qualified-object:ast @ ~] -.a)
|
|
|
|
%= $
|
|
|
|
profile [[-<.a (qualified-column:ast %qualified-column `qualified-object:ast`->+<.a ->+>-.a ~)] profile]
|
|
|
|
a +.a
|
|
|
|
==
|
|
|
|
?: =(%values ->.a)
|
|
|
|
?: =(~ -<.a)
|
|
|
|
?: =(~ +<.a) $(a ~)
|
|
|
|
~|("produce-matching-profile error: {<a>}" !!)
|
|
|
|
?@ -<-.a
|
|
|
|
?: ?=(datum:ast +<-.a)
|
2022-08-16 22:18:14 +03:00
|
|
|
%= $
|
2023-05-02 20:33:46 +03:00
|
|
|
profile [[-<-.a +<-.a] profile]
|
|
|
|
a [[-<+.a 'values'] +<+.a ~]
|
2022-08-16 22:18:14 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
~|("produce-matching-profile error on source: {<+<-.a>}" !!)
|
|
|
|
~|("produce-matching-profile error: {<a>}" !!)
|
|
|
|
~|("produce-matching-profile error: {<a>}" !!)
|
|
|
|
++ produce-matching
|
|
|
|
|= a=*
|
|
|
|
^- [(list matching:ast) (list matching:ast) (list matching:ast)]
|
|
|
|
=/ matched=(list matching:ast) ~
|
|
|
|
=/ not-matched-by-target=(list matching:ast) ~
|
|
|
|
=/ not-matched-by-source=(list matching:ast) ~
|
|
|
|
|-
|
|
|
|
?~ a
|
|
|
|
[(flop matched) (flop not-matched-by-target) (flop not-matched-by-source)]
|
|
|
|
?> ?=(matching-action:ast ->-.a)
|
|
|
|
?- `matching-action:ast`->-.a
|
|
|
|
%insert
|
|
|
|
?: ?=([%matched @ *] -.a)
|
2022-08-16 22:18:14 +03:00
|
|
|
%= $
|
2023-05-02 20:33:46 +03:00
|
|
|
matched [(matching:ast %matching predicate=~ matching-profile=[->-.a (produce-matching-profile ->+.a)]) matched]
|
|
|
|
a +.a
|
2022-08-16 22:18:14 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
?: =(%unmatch-target -<.a)
|
2022-12-01 00:51:43 +03:00
|
|
|
%= $
|
2023-05-02 20:33:46 +03:00
|
|
|
not-matched-by-target [(matching:ast %matching predicate=~ matching-profile=[->-.a (produce-matching-profile ->+.a)]) not-matched-by-target]
|
|
|
|
a +.a
|
2022-08-23 03:53:59 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
?: ?&(=(%matched -<-.a) =(%predicate -<+<.a))
|
2022-12-01 00:51:43 +03:00
|
|
|
%= $
|
2023-05-02 20:33:46 +03:00
|
|
|
matched [(matching:ast %matching predicate=`(produce-predicate (predicate-list -<+>.a)) matching-profile=[->-.a (produce-matching-profile ->+.a)]) matched]
|
|
|
|
a +.a
|
2022-08-23 03:53:59 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
~|("merge insert can't get here: {<-.a>}" !!)
|
|
|
|
%update
|
|
|
|
?: ?=([%matched @ *] -.a)
|
2022-12-01 00:51:43 +03:00
|
|
|
%= $
|
2023-05-02 20:33:46 +03:00
|
|
|
matched [(matching:ast %matching predicate=~ matching-profile=[->-.a (produce-matching-profile ->+.a)]) matched]
|
|
|
|
a +.a
|
2022-09-05 20:26:35 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
?: ?&(=(%matched -<-.a) =(%predicate -<+<.a))
|
2022-12-01 00:51:43 +03:00
|
|
|
%= $
|
2023-05-02 20:33:46 +03:00
|
|
|
matched [(matching:ast %matching predicate=`(produce-predicate (predicate-list -<+>.a)) matching-profile=[->-.a (produce-matching-profile ->+.a)]) matched]
|
|
|
|
a +.a
|
2022-09-05 20:26:35 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
~|("merge update can't get here: {<-.a>}" !!)
|
|
|
|
%delete
|
|
|
|
?: ?=([%matched @ *] -.a)
|
2022-12-01 00:51:43 +03:00
|
|
|
%= $
|
2023-05-02 20:33:46 +03:00
|
|
|
matched [(matching:ast %matching predicate=~ matching-profile=%delete) matched]
|
|
|
|
a +.a
|
2022-08-23 18:59:52 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
?: =(%unmatch-target -<.a)
|
2022-12-01 00:51:43 +03:00
|
|
|
%= $
|
2023-05-02 20:33:46 +03:00
|
|
|
not-matched-by-target [(matching:ast %matching predicate=~ matching-profile=%delete) not-matched-by-target]
|
|
|
|
a +.a
|
2022-08-23 18:59:52 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
?: ?&(=(%matched -<-.a) =(%predicate -<+<.a))
|
|
|
|
%= $
|
|
|
|
matched [(matching:ast %matching predicate=`(produce-predicate (predicate-list -<+>.a)) matching-profile=%delete) matched]
|
|
|
|
a +.a
|
2022-08-23 18:59:52 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
~|("merge delete can't get here: {<-.a>}" !!)
|
|
|
|
==
|
|
|
|
++ update-column-inner ;~ pose
|
|
|
|
;~(plug sym ;~(pfix whitespace ;~(pfix (jest '=') ;~(pfix whitespace ;~(pose parse-qualified-column parse-value-literal)))))
|
|
|
|
==
|
|
|
|
++ produce-column-sets
|
|
|
|
|= a=*
|
|
|
|
^- [(list @t) (list datum:ast)]
|
|
|
|
=/ columns=(list @t) ~
|
|
|
|
=/ values=(list datum:ast) ~
|
|
|
|
|-
|
|
|
|
?: =(a ~)
|
|
|
|
[columns values]
|
|
|
|
?: ?&(?=(datum:ast ->.a) ?=(@ -<.a))
|
|
|
|
%= $
|
|
|
|
columns [-<.a columns]
|
|
|
|
values [->.a values]
|
|
|
|
a +.a
|
|
|
|
==
|
|
|
|
~|("cannot parse column setting {<a>}" !!)
|
|
|
|
++ produce-update
|
|
|
|
|= a=*
|
|
|
|
^- update:ast
|
|
|
|
=/ table=qualified-object:ast ?>(?=(qualified-object:ast -.a) -.a)
|
|
|
|
=/ columns-values=[(list @t) (list datum:ast)] (produce-column-sets +>-.a)
|
|
|
|
?~ +>+.a
|
2023-05-15 19:48:28 +03:00
|
|
|
(update:ast %update table -.columns-values +.columns-values ~)
|
|
|
|
(update:ast %update table -.columns-values +.columns-values `(produce-predicate (predicate-list +>+.a)))
|
2023-05-02 20:33:46 +03:00
|
|
|
++ update-column ;~ pose
|
|
|
|
;~(pfix whitespace ;~(sfix update-column-inner whitespace))
|
|
|
|
;~(pfix whitespace update-column-inner)
|
|
|
|
;~(sfix update-column-inner whitespace)
|
|
|
|
update-column-inner
|
|
|
|
==
|
|
|
|
++ parse-update ;~ plug
|
|
|
|
;~(pfix whitespace parse-qualified-object)
|
|
|
|
(cold %set ;~(plug whitespace (jester 'set')))
|
|
|
|
(more com update-column)
|
|
|
|
;~ pose
|
|
|
|
;~(pfix ;~(plug whitespace (jester 'where')) parse-predicate)
|
|
|
|
(easy ~)
|
2022-08-16 22:18:14 +03:00
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
2023-05-16 22:59:29 +03:00
|
|
|
++ with-stop ;~ pose
|
|
|
|
;~(plug (jester 'delete') whitespace)
|
|
|
|
;~(plug (jester 'insert') whitespace)
|
|
|
|
;~(plug (jester 'merge') whitespace)
|
|
|
|
;~(plug (jester 'query') whitespace)
|
|
|
|
;~(plug (jester 'select') whitespace)
|
|
|
|
;~(plug (jester 'update') whitespace)
|
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
++ parse-with ;~ plug
|
|
|
|
parse-ctes
|
2023-05-16 22:59:29 +03:00
|
|
|
;~ pose
|
|
|
|
;~(plug (cold %delete ;~(plug (jester 'delete') whitespace (jester 'from'))) parse-delete)
|
|
|
|
;~(plug (jester 'delete') parse-delete)
|
|
|
|
;~(plug (cold %insert ;~(plug (jester 'insert') whitespace (jester 'into'))) parse-insert)
|
|
|
|
;~(plug (cold %merge ;~(plug (jester 'merge') whitespace (jester 'into'))) parse-merge)
|
|
|
|
;~(plug (cold %merge ;~(plug (jester 'merge') whitespace (jester 'from'))) parse-merge)
|
|
|
|
;~(plug (jester 'merge') parse-merge)
|
|
|
|
;~(plug (cold %query ;~(plug (jester 'from'))) parse-query)
|
|
|
|
;~(plug (cold %query ;~(plug ;~(pfix (jester 'select') (funk "select" (easy ' '))))) parse-query)
|
|
|
|
;~(plug (jester 'update') parse-update)
|
|
|
|
==
|
2023-05-02 20:33:46 +03:00
|
|
|
==
|
|
|
|
++ parse-revoke ;~ plug
|
|
|
|
:: permission
|
|
|
|
;~(pfix whitespace ;~(pose (jester 'adminread') (jester 'readonly') (jester 'readwrite') (jester 'all')))
|
|
|
|
:: revokee
|
|
|
|
;~(pfix whitespace ;~(pfix (jester 'from') ;~(pfix whitespace ;~(pose (jester 'parent') (jester 'siblings') (jester 'moons') (jester 'all') (stag %ships ship-list)))))
|
|
|
|
;~(sfix grant-object end-or-next-command)
|
|
|
|
==
|
|
|
|
++ parse-truncate-table ;~ sfix
|
|
|
|
;~(pfix whitespace parse-qualified-object)
|
|
|
|
end-or-next-command
|
|
|
|
==
|
2022-08-13 05:13:25 +03:00
|
|
|
--
|