urQL/urql/lib/parse.hoon

1948 lines
78 KiB
Plaintext
Raw Normal View History

2022-08-12 21:08:20 +03:00
/- ast
2022-10-21 20:44:14 +03:00
!:
2022-08-21 03:29:26 +03:00
|_ current-database=@t :: (parse:parse(current-database '<db>') "<script>")
::
:: generic urQL command
::
2022-08-12 21:08:20 +03:00
+$ command-ast
$%
2022-09-07 22:25:00 +03:00
alter-index:ast
alter-namespace:ast
2022-09-08 23:48:02 +03:00
alter-table:ast
2022-08-13 05:00:44 +03:00
create-database:ast
create-index:ast
create-namespace:ast
create-table:ast
create-view:ast
2022-08-16 22:18:14 +03:00
drop-database:ast
drop-index:ast
drop-namespace:ast
drop-table:ast
drop-view:ast
2022-08-23 03:53:59 +03:00
grant:ast
2022-09-04 20:53:13 +03:00
insert:ast
2023-01-05 21:17:42 +03:00
simple-query:ast
2022-08-23 18:59:52 +03:00
revoke:ast
2022-08-17 20:10:50 +03:00
truncate-table:ast
2022-08-12 21:08:20 +03:00
==
+$ command
$%
2022-09-07 22:25:00 +03:00
%alter-index
%alter-namespace
2022-09-08 23:48:02 +03:00
%alter-table
2022-08-12 21:08:20 +03:00
%create-database
%create-index
%create-namespace
%create-table
%create-view
2022-08-16 22:18:14 +03:00
%drop-database
%drop-index
%drop-namespace
%drop-table
%drop-view
2022-08-23 03:53:59 +03:00
%grant
2022-09-04 20:53:13 +03:00
%insert
2022-09-12 22:38:25 +03:00
%query
2022-08-23 18:59:52 +03:00
%revoke
2022-08-17 20:10:50 +03:00
%truncate-table
2022-08-12 21:08:20 +03:00
==
2022-08-13 05:00:44 +03:00
::
:: helper types
::
2022-12-01 00:51:43 +03:00
+$ interim-key
$:
%interim-key
2022-09-02 03:14:57 +03:00
is-clustered=?
columns=(list ordered-column:ast)
==
2022-12-01 00:51:43 +03:00
::+$ expression ?(qualified-column:ast value-literal:ast value-literal-list:ast aggregate:ast) :: fish-loop
+$ expression ?(qualified-column:ast value-literal:ast value-literal-list:ast) :: aggregate:ast)
+$ parens ?(%pal %par)
+$ raw-predicate-component ?(parens predicate-component:ast predicate:ast)
2023-01-05 21:17:42 +03:00
+$ raw-predicate-component2 ?(%pal %par ternary-operator:ast binary-operator:ast unary-operator:ast conjunction:ast qualified-column:ast value-literal:ast value-literal-list:ast)
2022-09-25 18:52:01 +03:00
+$ list6
$:
%list6
2022-12-01 00:51:43 +03:00
l1=raw-predicate-component
l2=raw-predicate-component
l3=raw-predicate-component
l4=raw-predicate-component
l5=raw-predicate-component
l6=raw-predicate-component
2022-09-25 18:52:01 +03:00
==
+$ list5
$:
%list5
2022-12-01 00:51:43 +03:00
l1=raw-predicate-component
l2=raw-predicate-component
l3=raw-predicate-component
l4=raw-predicate-component
l5=raw-predicate-component
2022-09-25 18:52:01 +03:00
==
+$ list4
$:
%list4
2022-12-01 00:51:43 +03:00
l1=raw-predicate-component
l2=raw-predicate-component
l3=raw-predicate-component
l4=raw-predicate-component
2022-09-25 18:52:01 +03:00
==
+$ try-fail %fail
+$ try-success
$:
%try-success
2022-12-01 00:51:43 +03:00
result=raw-predicate-component
2022-09-25 18:52:01 +03:00
==
2022-12-01 00:51:43 +03:00
+$ try-result $%(try-success try-fail)
::
2022-08-22 00:09:24 +03:00
:: get next position in script
::
++ get-next-cursor
|= [last-cursor=[@ud @ud] command-hair=[@ud @ud] end-hair=[@ud @ud]]
^- [@ud @ud]
=/ next-hair ?: (gth -.command-hair 1) :: if we advanced to next input line
[(sub (add -.command-hair -.last-cursor) 1) +.command-hair] :: add lines and use last column
[-.command-hair (sub (add +.command-hair +.last-cursor) 1)] :: else add column positions
?: (gth -.end-hair 1) :: if we advanced to next input line
[(sub (add -.next-hair -.end-hair) 1) +.end-hair] :: add lines and use last column
[-.next-hair (sub (add +.next-hair +.end-hair) 1)] :: else add column positions
2022-09-02 03:14:57 +03:00
::
2022-08-17 20:10:50 +03:00
:: parser rules and helpers
2022-08-16 22:18:14 +03:00
::
++ whitespace ~+ (star ;~(pose gah (just '\09') (just '\0d')))
2022-12-01 00:51:43 +03:00
++ prn-less-soz ~+ ;~(less (just `@`39) (just `@`127) (shim 32 256))
++ crub-no-text :: crub:so without text parsing
2022-09-04 20:53:13 +03:00
~+
;~ 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)
==
2023-01-11 02:26:55 +03:00
::++ select-rule :: does not build
:: |* text=tape
:: ^- rule
:: ;~(pfix (jest 'select') (funk "select" (easy text)))
2022-08-17 20:10:50 +03:00
++ jester :: match a cord, case agnostic, thanks ~tinnus-napbus
2022-08-16 22:18:14 +03:00
|= daf=@t
|= tub=nail
2022-10-23 23:12:24 +03:00
~+
2022-08-16 22:18:14 +03:00
=+ fad=daf
|- ^- (like @t)
?: =(`@`0 daf)
[p=p.tub q=[~ u=[p=fad q=tub]]]
2022-08-17 20:10:50 +03:00
=+ n=(end 3 daf)
2022-12-01 00:51:43 +03:00
?. ?& ?=(^ q.tub)
2022-08-17 20:10:50 +03:00
?| =(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))
==
==
2022-08-16 22:18:14 +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
::
2022-09-02 03:14:57 +03:00
++ cook-qualified-2object :: namespace.object-name
|= a=*
~+
?@ a
(qualified-object:ast %qualified-object ~ current-database 'dbo' a)
(qualified-object:ast %qualified-object ~ current-database -.a +.a)
2022-08-28 18:58:03 +03:00
++ cook-qualified-3object :: database.namespace.object-name
2022-08-22 06:25:18 +03:00
|= a=*
2022-08-28 18:58:03 +03:00
~+
2022-09-12 22:38:25 +03:00
?: ?=([@ @ @] 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
(qualified-object:ast %qualified-object ~ current-database -.a +.a)
?@ a :: name
(qualified-object:ast %qualified-object ~ current-database 'dbo' a)
2022-12-01 02:06:42 +03:00
~|("cannot parse qualified-object {<a>}" !!)
2022-08-28 18:58:03 +03:00
++ cook-qualified-object :: @p.database.namespace.object-name
2022-08-21 03:29:26 +03:00
|= a=*
2022-08-28 18:58:03 +03:00
~+
2022-09-12 22:38:25 +03:00
?: ?=([@ @ @ @] 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)
2022-12-01 00:51:43 +03:00
?: ?=([@ @ @] a)
2022-09-12 22:38:25 +03:00
(qualified-object:ast %qualified-object ~ -.a +<.a +>.a) :: db.ns.name
?: ?=([@ @] a) :: ns.name
(qualified-object:ast %qualified-object ~ current-database -.a +.a)
?@ a :: name
(qualified-object:ast %qualified-object ~ current-database 'dbo' a)
2022-12-01 02:06:42 +03:00
~|("cannot parse qualified-object {<a>}" !!)
2022-10-23 23:12:24 +03:00
++ qualified-namespace :: database.namespace
|= [a=* current-database=@t]
~+
?: ?=([@ @] [a])
a
[current-database a]
++ parse-qualified-2-name ~+ ;~(pose ;~(pfix whitespace ;~((glue dot) sym sym)) parse-face)
++ parse-qualified-3 ~+ ;~ pose :: for when qualifying with ship is not allowed
;~((glue dot) sym sym sym)
;~(plug sym dot dot sym)
;~((glue dot) sym sym)
sym
==
++ parse-qualified-3object ~+ (cook cook-qualified-3object ;~(pfix whitespace parse-qualified-3))
2022-10-23 23:12:24 +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))
::
2022-09-25 18:52:01 +03:00
:: working with atomic value literals
::
2022-12-01 00:51:43 +03:00
++ cord-literal ~+
2022-09-25 18:52:01 +03:00
(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
(stag %rs (full royl-rs:so)) :: @rs
(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)
(scan a numeric-parser)
++ sear-numbers :: works for predicate values
2022-09-04 20:53:13 +03:00
|= a=(list @t)
=/ parsed (numeric-parser [[1 1] a])
?~ q.parsed ~
2022-12-01 00:51:43 +03:00
(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))
2022-10-23 23:12:24 +03:00
++ parse-value-literal ;~ pose
non-numeric-parser
(sear sear-numbers numeric-characters) :: all numeric parsers
==
++ insert-value ~+ ;~ pose
2022-09-05 20:26:35 +03:00
(cold [%default %default] (jester 'default'))
;~(pose non-numeric-parser (cook cook-numbers numeric-characters))
2022-09-04 20:53:13 +03:00
==
2022-10-24 01:05:57 +03:00
++ get-value-literal ;~ pose :: changing to ifix here slowed down test cases
2022-09-25 18:52:01 +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
2022-09-30 23:31:56 +03:00
:: 1. all literal types must be the same
2022-09-25 18:52:01 +03:00
::
2022-09-30 23:31:56 +03:00
:: 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
2022-09-25 18:52:01 +03:00
::
|= a=(list value-literal:ast)
2022-12-01 00:51:43 +03:00
~+
2022-09-25 18:52:01 +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))
2022-12-01 02:06:42 +03:00
~|("cannot parse literal-list {<a>}" !!)
2022-10-23 23:12:24 +03:00
++ value-literal-list ~+
2022-09-25 18:52:01 +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))))
2022-10-24 01:05:57 +03:00
++ parse-insert-value ;~ pose
;~(pfix whitespace ;~(sfix insert-value whitespace))
;~(pfix whitespace insert-value)
;~(sfix insert-value whitespace)
insert-value
2022-09-04 20:53:13 +03:00
==
2022-09-25 18:52:01 +03:00
::
:: used for various commands
::
++ cook-column
|= a=*
2022-12-01 00:51:43 +03:00
?: ?=([@ @] [a])
2022-09-25 18:52:01 +03:00
(column:ast %column -.a +.a)
2022-12-01 02:06:42 +03:00
~|("cannot parse column {<a>}" !!)
2022-09-25 18:52:01 +03:00
++ cook-ordered-column
|= a=*
?@ a
(ordered-column:ast %ordered-column a %.y)
?: ?=([@ @] [a])
2022-12-01 00:51:43 +03:00
?: =(+.a %asc)
2022-09-25 18:52:01 +03:00
(ordered-column:ast %ordered-column -.a %.y)
(ordered-column:ast %ordered-column -.a %.n)
2022-12-01 02:06:42 +03:00
~|("cannot parse ordered-column {<a>}" !!)
2022-09-25 18:52:01 +03:00
++ cook-referential-integrity
|= a=*
2022-12-01 00:51:43 +03:00
?: ?=([[@ @] @ @] [a]) :: <type> cascade, <type> cascade
2022-09-25 18:52:01 +03:00
?: =(%delete -<.a)
2022-12-01 00:51:43 +03:00
?: =(%update +<.a)
2022-09-25 18:52:01 +03:00
~[%delete-cascade %update-cascade]
!!
?: =(%update -<.a)
2022-12-01 00:51:43 +03:00
?: =(%delete +<.a)
2022-09-25 18:52:01 +03:00
~[%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
~
2022-12-01 02:06:42 +03:00
~|("cannot parse ordered-column {<a>}" !!)
2022-10-31 05:52:27 +03:00
++ end-or-next-command ;~ plug
(cold %end-command ;~(pose ;~(plug whitespace mic) whitespace mic))
(easy ~)
==
2022-10-23 23:12:24 +03:00
++ alias
2022-09-12 22:38:25 +03:00
%+ cook
|=(a=tape (rap 3 ^-((list ,@) a)))
;~(plug alf (star ;~(pose nud alf)))
2022-10-23 23:12:24 +03:00
++ parse-alias ;~(pfix whitespace alias)
++ parse-face ;~(pfix whitespace sym)
2022-09-02 03:14:57 +03:00
++ face-list ~+ ;~(pfix whitespace (ifix [pal par] (more com ;~(pose ;~(sfix parse-face whitespace) parse-face))))
2022-08-28 18:58:03 +03:00
++ ordering ~+ ;~(pfix whitespace ;~(pose (jester 'asc') (jester 'desc')))
2022-09-04 20:53:13 +03:00
++ clustering ~+ ;~(pfix whitespace ;~(pose (jester 'clustered') (jester 'nonclustered')))
++ ordered-column-list ~+
;~(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)))))
2022-08-28 18:58:03 +03:00
++ parse-ship ~+ ;~(pfix sig fed:ag)
2022-09-04 20:53:13 +03:00
++ ship-list ~+ (more com ;~(pose ;~(sfix ;~(pfix whitespace parse-ship) whitespace) ;~(pfix whitespace parse-ship) ;~(sfix parse-ship whitespace) parse-ship))
2022-08-28 18:58:03 +03:00
++ on-database ~+ ;~(plug (jester 'database') parse-face)
++ on-namespace ~+
;~(plug (jester 'namespace') (cook |=(a=* (qualified-namespace [a current-database])) parse-qualified-2-name))
2022-08-28 18:58:03 +03:00
++ grant-object ~+
;~(pfix whitespace ;~(pfix (jester 'on') ;~(pfix whitespace ;~(pose on-database on-namespace parse-qualified-3object))))
2022-12-01 00:51:43 +03:00
++ parse-aura ~+
=/ root-aura ;~ pose
(jest '@c')
(jest '@da')
(jest '@dr')
2022-12-01 00:51:43 +03:00
(jest '@d')
(jest '@f')
(jest '@if')
(jest '@is')
2022-12-01 00:51:43 +03:00
(jest '@i')
(jest '@n')
(jest '@p')
(jest '@q')
(jest '@rh')
(jest '@rs')
(jest '@rd')
(jest '@rq')
2022-12-01 00:51:43 +03:00
(jest '@r')
(jest '@sb')
(jest '@sd')
(jest '@sv')
(jest '@sw')
(jest '@sx')
2022-12-01 00:51:43 +03:00
(jest '@s')
(jest '@ta')
(jest '@tas')
2022-12-01 00:51:43 +03:00
(jest '@t')
(jest '@ub')
(jest '@ud')
(jest '@uv')
(jest '@uw')
(jest '@ux')
2022-12-01 00:51:43 +03:00
(jest '@u')
(jest '@')
==
;~ pose
;~(plug root-aura (shim 'A' 'J'))
root-aura
==
++ column-defintion-list ~+
=/ column-definition ;~ plug
sym
;~(pfix whitespace parse-aura)
2022-12-01 00:51:43 +03:00
==
(more com (cook cook-column ;~(pose ;~(pfix whitespace ;~(sfix column-definition whitespace)) ;~(sfix column-definition whitespace) ;~(pfix whitespace column-definition) column-definition)))
2022-12-01 00:51:43 +03:00
++ 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'))))
==
++ column-definitions ~+ ;~(pfix whitespace (ifix [pal par] column-defintion-list))
2022-12-01 00:51:43 +03:00
++ alter-columns ~+ ;~ plug
(cold %alter-column ;~(plug whitespace (jester 'alter') whitespace (jester 'column')))
column-definitions
==
2022-12-01 00:51:43 +03:00
++ add-columns ~+ ;~ plug
(cold %add-column ;~(plug whitespace (jester 'add') whitespace (jester 'column')))
column-definitions
2022-09-04 20:53:13 +03:00
==
2022-12-01 00:51:43 +03:00
++ drop-columns ~+ ;~ plug
(cold %drop-column ;~(plug whitespace (jester 'drop') whitespace (jester 'column')))
face-list
==
2022-10-16 02:09:57 +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-21 20:44:14 +03:00
++ cook-aggregate
|= parsed=*
(aggregate:ast %aggregate -.parsed +.parsed)
2022-10-23 23:12:24 +03:00
++ parse-aggregate ;~ pose
2022-10-22 01:37:24 +03:00
(cook cook-aggregate ;~(pfix whitespace ;~(plug ;~(sfix parse-alias pal) ;~(sfix get-datum par))))
2022-10-21 20:44:14 +03:00
(cook cook-aggregate ;~(plug ;~(sfix parse-alias pal) ;~(sfix get-datum par)))
2022-10-22 01:37:24 +03:00
==
::
:: indices
::
++ cook-primary-key
|= a=*
2022-10-23 23:12:24 +03:00
~+
?@ -.a
?: =(-.a 'clustered') (interim-key %interim-key %.y +.a) (interim-key %interim-key %.n +.a)
(interim-key %interim-key %.n a)
++ cook-foreign-key
|= a=*
~+
2022-12-01 00:51:43 +03:00
?: ?=([[@ * * [@ @] *] *] [a]) :: foreign key ns.table ... references fk-table ... on action on action
(foreign-key:ast %foreign-key -<.a ->-.a ->+<-.a ->+<+.a ->+>.a +.a)
2022-12-01 00:51:43 +03:00
?: ?=([[@ [[@ @ @] %~] @ [@ %~]] *] [a]) :: foreign key table ... references fk-table ... on action on action
(foreign-key:ast %foreign-key -<.a ->-.a ->+<-.a 'dbo' ->+.a +.a)
2022-12-01 02:06:42 +03:00
~|("cannot parse foreign-key {<a>}" !!)
2022-09-07 01:46:28 +03:00
++ build-foreign-keys
|= a=[table=qualified-object:ast f-keys=(list *)]
2022-10-23 23:12:24 +03:00
~+
2022-09-07 01:46:28 +03:00
=/ f-keys +.a
=/ foreign-keys `(list foreign-key:ast)`~
|-
?: =(~ f-keys)
2022-09-10 02:30:41 +03:00
(flop foreign-keys)
2022-09-07 01:46:28 +03:00
?@ -<.f-keys
2022-12-01 00:51:43 +03:00
%= $ :: foreign key table must be in same DB as table
2022-09-07 01:46:28 +03:00
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
==
2022-12-01 00:51:43 +03:00
%= $ :: foreign key table must be in same DB as table
2022-09-07 01:46:28 +03:00
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
==
2022-12-01 00:51:43 +03:00
++ foreign-key-literal ~+ ;~(plug whitespace (jester 'foreign') whitespace (jester 'key'))
2022-09-10 02:30:41 +03:00
++ foreign-key ~+
;~(plug parse-face ordered-column-list ;~(pfix ;~(plug whitespace (jester 'references')) ;~(plug (cook cook-qualified-2object parse-qualified-2-name) face-list)))
2022-10-23 23:12:24 +03:00
++ full-foreign-key ~+ ;~ pose
2022-09-07 01:46:28 +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-12-01 00:51:43 +03:00
++ add-foreign-key ~+ ;~ plug
(cold %add-fk ;~(plug whitespace (jester 'add')))
2022-09-10 02:30:41 +03:00
;~(pfix foreign-key-literal (more com full-foreign-key))
2022-09-08 23:48:02 +03:00
==
2022-12-01 00:51:43 +03:00
++ drop-foreign-key ~+ ;~ plug
(cold %drop-fk ;~(plug whitespace (jester 'drop') whitespace (jester 'foreign') whitespace (jester 'key')))
2022-09-08 23:48:02 +03:00
face-list
==
2022-10-23 23:12:24 +03:00
++ primary-key ~+
2022-09-10 02:30:41 +03:00
(cook cook-primary-key ;~(pfix ;~(plug whitespace (jester 'primary') whitespace (jester 'key')) ;~(pose ;~(plug clustering ordered-column-list) ordered-column-list)))
++ create-primary-key
|= a=[[@ ship=(unit @p) database=@t namespace=@t name=@t] key=*]
2022-10-23 23:12:24 +03:00
~+
2022-09-10 02:30:41 +03:00
=/ key-name (crip (weld (weld "ix-primary-" (trip namespace.a)) (weld "-" (trip name.a))))
(create-index:ast %create-index key-name (qualified-object:ast %qualified-object ~ database.a namespace.a name.a) %.y +<:key.a +>:key.a)
::
2022-09-25 18:52:01 +03:00
:: query object and joins
::
2022-12-01 00:51:43 +03:00
++ join-stop ;~ pose
2022-11-07 03:56:54 +03:00
(jester 'scalar')
(jester 'select')
2022-12-01 00:51:43 +03:00
(jester 'join')
(jester 'left')
(jester 'right')
(jester 'outer')
2022-11-07 03:56:54 +03:00
(jester 'cross')
==
2022-12-01 00:51:43 +03:00
++ query-object ~+ ;~ pose
;~(plug parse-qualified-object ;~(pfix whitespace ;~(pfix (jester 'as') parse-alias)))
;~(plug parse-qualified-object ;~(pfix whitespace ;~(less join-stop parse-alias)))
2022-09-25 18:52:01 +03:00
parse-qualified-object
==
2022-09-12 22:38:25 +03:00
++ parse-query-object ~+ ;~ pfix
2022-12-01 00:51:43 +03:00
whitespace
2022-09-25 18:52:01 +03:00
(cook build-query-object query-object)
2022-09-12 22:38:25 +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-23 23:12:24 +03:00
++ parse-cross-join-type ~+ ;~ pfix
2022-09-25 18:52:01 +03:00
whitespace
(cold %cross-join ;~(plug (jester 'cross') whitespace (jester 'join')))
==
++ build-query-object ~+
|= parsed=*
?: ?=([@ @ @ @ @] parsed)
2022-12-01 00:51:43 +03:00
(query-object:ast %query-object parsed ~)
?: ?=([[@ @ @ @ @] @] parsed)
2022-12-01 00:51:43 +03:00
(query-object:ast %query-object -.parsed `+.parsed)
2022-12-01 02:06:42 +03:00
~|("cannot parse query-object {<parsed>}" !!)
2022-12-01 00:51:43 +03:00
++ parse-cross-joined-object ~+ ;~(plug parse-cross-join-type parse-query-object)
::(cook cook-joined-object ;~(plug parse-cross-join-type parse-query-object))
++ parse-joined-object ~+ ;~ plug
parse-join-type
2022-09-25 18:52:01 +03:00
parse-query-object
;~(pfix whitespace ;~(pfix (jester 'on') parse-predicate))
2022-12-01 00:51:43 +03:00
::;~(pfix whitespace ;~(pfix (jester 'on') ;~(less predicate-stop prn)))
2023-01-05 21:17:42 +03:00
::(easy ~)
2022-09-25 18:52:01 +03:00
==
2022-12-01 00:51:43 +03:00
++ build-joined-object parse-joined-object
::(cook cook-joined-object parse-joined-object)
::++ cook-joined-object
:: |= parsed=*
:: ~+
:: ~| "-.parsed: {<-.parsed>}"
:: ~| "+<.parsed: {<+<.parsed>}"
:: ~| "+>.parsed: {<+>.parsed>}"
:: ^- joined-object:ast
:: ?> ?=(join-type:ast -.parsed)
:: ?: ?&(?=([@ @ [@ @ @ @ @] @ @] parsed) ?=(query-object:ast +.parsed))
:: (joined-object:ast %joined-object -.parsed +.parsed ~)
:: ?: ?&(?=([@ @ [@ @ @ @ @] @] parsed) ?=(query-object:ast +.parsed))
:: (joined-object:ast %joined-object -.parsed +.parsed ~)
:: (joined-object:ast %joined-object -.parsed +<.parsed (produce-predicate (predicate-list +>.parsed)))
2023-01-11 02:26:55 +03:00
++ parse-object-and-joins ~+ ;~ plug
2022-09-25 18:52:01 +03:00
parse-query-object
;~(pose parse-cross-joined-object (star build-joined-object))
==
::
:: column in "join on" or "where" predicate, qualified or aliased
:: indeterminate qualification and aliasing is determined later
::
++ cook-qualified-column
|= a=*
~+
?: ?=([@ @ @ @ @] 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
(qualified-column:ast %qualified-column (qualified-object:ast %qualified-object ~ current-database -.a +<.a) +>.a ~)
2022-09-25 18:52:01 +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 ~)
2022-12-01 02:06:42 +03:00
~|("cannot parse qualified-column {<a>}" !!)
2022-10-23 23:12:24 +03:00
++ parse-column ~+ ;~ pose
2022-12-01 00:51:43 +03:00
;~((glue dot) parse-ship sym sym sym sym)
;~(plug parse-ship ;~(pfix dot sym) dot dot sym ;~(pfix dot sym))
2022-09-12 22:38:25 +03:00
;~((glue dot) sym sym sym sym)
;~(plug sym dot ;~(pfix dot sym) ;~(pfix dot sym))
2022-09-12 22:38:25 +03:00
;~((glue dot) sym sym sym)
;~(plug mixed-case-symbol ;~(pfix dot sym))
2022-09-12 22:38:25 +03:00
sym
==
2022-10-17 00:31:55 +03:00
++ parse-qualified-column ~+ (cook cook-qualified-column parse-column)
2022-09-25 18:52:01 +03:00
::
:: predicate
::
2022-12-01 00:51:43 +03:00
++ parse-operator ~+ ;~ pose
2022-09-25 18:52:01 +03:00
:: 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))
2022-12-01 00:51:43 +03:00
(cold %all ;~(plug (jester 'all') whitespace))
2022-09-25 18:52:01 +03:00
:: 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))
2023-01-05 21:17:42 +03:00
:: (cold %distinct ;~(plug (jester 'is') whitespace (jester 'distinct') whitespace (jester 'from')))
:: (cold %not-distinct ;~(plug (jester 'is') whitespace (jester 'not') whitespace (jester 'distinct') whitespace (jester 'from')))
2022-09-25 18:52:01 +03:00
:: ternary operator
2022-12-01 00:51:43 +03:00
(cold %between ;~(plug (jester 'between') whitespace))
2022-09-25 18:52:01 +03:00
:: nesting directors
(cold %pal pal)
(cold %par par)
==
++ resolve-between-operator
|= [operator=ternary-operator:ast c1=expression c2=expression c3=expression]
2022-10-23 23:12:24 +03:00
~+
2022-09-25 18:52:01 +03:00
^- (tree predicate-component:ast)
=/ left `(tree predicate-component:ast)`[%gte `(tree predicate-component:ast)`[c1 ~ ~] `(tree predicate-component:ast)`[c2 ~ ~]]
=/ right `(tree predicate-component:ast)`[%lte `(tree predicate-component:ast)`[c1 ~ ~] `(tree predicate-component:ast)`[c3 ~ ~]]
`(tree predicate-component:ast)`[operator left right]
++ resolve-not-between-operator
|= [operator=ternary-operator:ast c1=expression c2=expression c3=expression]
2022-10-23 23:12:24 +03:00
~+
2022-09-25 18:52:01 +03:00
^- (tree predicate-component:ast)
=/ left `(tree predicate-component:ast)`[%gte `(tree predicate-component:ast)`[c1 ~ ~] `(tree predicate-component:ast)`[c2 ~ ~]]
=/ right `(tree predicate-component:ast)`[%lte `(tree predicate-component:ast)`[c1 ~ ~] `(tree predicate-component:ast)`[c3 ~ ~]]
`(tree predicate-component:ast)`[%not `(tree predicate-component:ast)`[operator left right] ~]
++ resolve-binary-operator
|= [operator=binary-operator:ast c1=expression c2=expression]
2022-10-23 23:12:24 +03:00
~+
2022-09-25 18:52:01 +03:00
^- (tree predicate-component:ast)
2022-12-01 00:51:43 +03:00
`(tree predicate-component:ast)`[operator `(tree predicate-component:ast)`[`predicate-component:ast`c1 ~ ~] `(tree predicate-component:ast)`[`predicate-component:ast`c2 ~ ~]]
2022-09-25 18:52:01 +03:00
++ resolve-all-any
|= b=[l1=expression l2=inequality-operator:ast l3=all-any-operator:ast l4=expression]
2022-10-23 23:12:24 +03:00
~+
2022-09-25 18:52:01 +03:00
^- (tree predicate-component:ast)
=/ all-any `(tree predicate-component:ast)`[l3.b `(tree predicate-component:ast)`[l4.b ~ ~] ~]
`(tree predicate-component:ast)`[l2.b `(tree predicate-component:ast)`[l1.b ~ ~] all-any]
++ try-not-between-and
|= b=list6
2022-10-23 23:12:24 +03:00
~+
2022-09-25 18:52:01 +03:00
^- try-result
?. ?&(?=(expression l1.b) ?=(%not l2.b) ?=(ternary-operator:ast l3.b) ?=(expression l4.b) ?=(%and l5.b) ?=(expression l6.b))
2022-09-25 18:52:01 +03:00
`try-result`%fail
2022-12-01 00:51:43 +03:00
(try-success %try-success (resolve-not-between-operator [l3.b l1.b l4.b l6.b]))
2022-09-25 18:52:01 +03:00
++ try-5
|= b=list5
2022-10-23 23:12:24 +03:00
~+
2022-09-25 18:52:01 +03:00
^- try-result
?: ?&(?=(expression l1.b) ?=(%not l2.b) ?=(ternary-operator:ast l3.b) ?=(expression l4.b) ?=(expression l5.b))
2022-12-01 00:51:43 +03:00
(try-success %try-success (resolve-not-between-operator [l3.b l1.b l4.b l5.b]))
?: ?&(?=(expression l1.b) ?=(ternary-operator:ast l2.b) ?=(expression l3.b) ?=(%and l4.b) ?=(expression l5.b))
2022-09-25 18:52:01 +03:00
(try-success %try-success (resolve-between-operator [l2.b l1.b l3.b l5.b]))
`try-result`%fail
++ try-4
|= b=list4
2022-10-23 23:12:24 +03:00
~+
2022-09-25 18:52:01 +03:00
^- try-result
:: expression between expression expression
?: ?&(?=(expression l1.b) ?=(ternary-operator:ast l2.b) ?=(expression l3.b) ?=(expression l4.b))
2022-09-25 18:52:01 +03:00
(try-success %try-success (resolve-between-operator [l2.b l1.b l3.b l4.b]))
:: expression inequality all/any cte-one-column-query
?: ?&(?=(expression l1.b) ?=(inequality-operator:ast l2.b) ?=(all-any-operator:ast l3.b) ?=(expression l4.b))
2022-09-25 18:52:01 +03:00
(try-success %try-success (resolve-all-any [l1.b l2.b l3.b l4.b]))
:: expression not in query or value list
?: ?&(?=(expression l1.b) ?=(%not l2.b) ?=(%in l3.b) ?=(expression l4.b))
2022-09-25 18:52:01 +03:00
(try-success %try-success `(tree predicate-component:ast)`[%not `(tree predicate-component:ast)`[%in [l1.b ~ ~] [l4.b ~ ~]] ~])
`try-result`%fail
++ resolve-operators
::
:: resolve non-unary (and some unary) operators into trees
2022-12-01 00:51:43 +03:00
|= a=(list raw-predicate-component)
2022-10-23 23:12:24 +03:00
~+
2022-12-01 00:51:43 +03:00
^- (list raw-predicate-component)
=/ resolved=(list raw-predicate-component) ~
2022-09-25 18:52:01 +03:00
=+ result=`try-result`%fail
=+ result2=`try-result`%fail
=+ result3=`try-result`%fail
|-
?: =(a ~) (flop resolved)
2022-12-01 00:51:43 +03:00
::
2022-09-25 18:52:01 +03:00
:: expression not between expression and expression
2022-12-01 00:51:43 +03:00
=. result ?: (gte (lent a) 6)
2022-09-25 18:52:01 +03:00
(try-not-between-and (list6 %list6 -.a +<.a +>-.a +>+<.a +>+>-.a +>+>+<.a))
`try-result`%fail
2022-12-01 00:51:43 +03:00
?. ?=(try-fail result) $(a +>+>+>.a, resolved [result.result resolved])
2022-09-25 18:52:01 +03:00
::
:: expression not between expression expression
:: expression between expression and expression
2022-12-01 00:51:43 +03:00
=. result2 ?: (gte (lent a) 5)
2022-09-25 18:52:01 +03:00
(try-5 (list5 %list5 -.a +<.a +>-.a +>+<.a +>+>-.a))
`try-result`%fail
2022-12-01 00:51:43 +03:00
?. ?=(try-fail result2) $(a +>+>+.a, resolved [result.result2 resolved])
2022-09-25 18:52:01 +03:00
::
:: expression between expression expression
:: expression inequality all/any cte-one-column-query
:: expression not in query or value list
2022-12-01 00:51:43 +03:00
=. result3 ?: (gte (lent a) 4)
2022-09-25 18:52:01 +03:00
(try-4 (list4 %list4 -.a +<.a +>-.a +>+<.a))
`try-result`%fail
2022-12-01 00:51:43 +03:00
?. ?=(try-fail result3) $(a +>+>.a, resolved [result.result3 resolved])
2022-09-25 18:52:01 +03:00
::
:: expression binary operator expression
?: ?&((gte (lent a) 3) ?=(expression -.a) ?=(binary-operator:ast +<.a) ?=(expression +>-.a))
2022-09-25 18:52:01 +03:00
$(a +>+.a, resolved [(resolve-binary-operator [+<.a -.a +>-.a]) resolved])
::
:: not exists column or cte-one-column-query
?: ?&((gte (lent a) 3) ?=(%not -.a) ?=(%exists +<.a) ?=(expression +>-.a))
2022-09-25 18:52:01 +03:00
$(a +>+.a, resolved [`(tree predicate-component:ast)`[%not `(tree predicate-component:ast)`[%exists [`(tree predicate-component:ast)`[+>-.a ~ ~]] ~] ~] resolved])
::
:: exists column or cte-one-column-query
?: ?&((gte (lent a) 2) ?=(%exists -.a) ?=(expression +<.a))
2022-09-25 18:52:01 +03:00
$(a +>.a, resolved [`(tree predicate-component:ast)`[%exists [`(tree predicate-component:ast)`[+<.a ~ ~]] ~] resolved])
$(a +.a, resolved [-.a resolved])
++ resolve-depth
::
:: determine deepest parenthesis nesting, eliminating superfluous nesting
2022-12-01 00:51:43 +03:00
|= a=(list raw-predicate-component)
2022-10-23 23:12:24 +03:00
~+
2022-12-01 00:51:43 +03:00
^- [@ud (list raw-predicate-component)]
=/ resolved=(list raw-predicate-component) ~
2022-09-25 18:52:01 +03:00
=/ depth 0
=/ working-depth 0
|-
?: =(a ~) [depth (flop resolved)]
?: =(-.a %pal)
?: ?&((gte (lent +.a) 2) =(+>-.a %par)) :: single parenthesised entity
$(a +>+.a, resolved [+<.a resolved])
?. (gth (add working-depth 1) depth) $(working-depth (add working-depth 1), a +.a, resolved [-.a resolved])
%= $
depth (add depth 1)
working-depth (add working-depth 1)
a +.a
resolved [-.a resolved]
==
?. =(-.a %par) $(a +.a, resolved [-.a resolved])
%= $
working-depth (sub working-depth 1)
a +.a
resolved [-.a resolved]
==
2022-09-27 20:07:16 +03:00
++ resolve-conjunctions
::
:: 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
::
2023-01-05 21:17:42 +03:00
|= a=[target-depth=@ud components=(list raw-predicate-component) predicates=(list predicate:ast)]
2022-12-01 00:51:43 +03:00
^- [(list raw-predicate-component) (list predicate:ast)]
2023-01-05 21:17:42 +03:00
::~& "(lent components.a): {<(lent components.a)>}"
::?: =((lent components.a) 1) [~ `(list predicate:ast)`[-.components.a ~]]
=/ resolved=(list raw-predicate-component) ~
=/ working-depth 0
=/ working-tree=predicate:ast ~
=/ resolved-trees=(list predicate:ast) ~
2022-09-27 20:07:16 +03:00
|-
2023-01-05 21:17:42 +03:00
?: =(components.a ~) [(flop resolved) (flop resolved-trees)]
?: ?&(=(-.components.a %pal) !=(+>-.components.a %par))
2022-12-01 00:51:43 +03:00
%= $
2023-01-05 21:17:42 +03:00
components.a +.components.a
resolved [-.components.a resolved]
2022-12-01 00:51:43 +03:00
working-depth (add working-depth 1)
==
2022-09-27 20:07:16 +03:00
?. =(working-depth target-depth.a)
2023-01-05 21:17:42 +03:00
$(components.a +.components.a, resolved [-.components.a resolved])
2022-09-27 20:07:16 +03:00
|-
::
:: if there are superfluous levels of nesting we will end up here
2022-12-01 00:51:43 +03:00
:: to do: test if this is still working/required
2023-01-05 21:17:42 +03:00
?: =(components.a ~) ^$(resolved [working-tree resolved])
2022-09-30 23:31:56 +03:00
::
:: if () enclosed tree is first thing, then it is always the left subtree
2023-01-05 21:17:42 +03:00
:: ~& "(lent components.a): {<(lent components.a)>}"
?: =(-.components.a %pal)
?: =(+>-.components.a %par)
2022-09-30 23:31:56 +03:00
:: stand-alone tree
2023-01-05 21:17:42 +03:00
?: =((lent components.a) 3)
%= ^$
components.a ~ :: end of comonents +>+.components.a
resolved [+<.components.a resolved]
:: working-tree -.resolved-trees (not necessary, we are at end)
resolved-trees +.resolved-trees
==
2022-12-01 00:51:43 +03:00
?: ?&((gth (lent resolved) 1) =(-.resolved %pal))
2023-01-05 21:17:42 +03:00
::$(components.a +>+.components.a, working-tree +<.components.a)
%= ^$
components.a +>+.components.a
working-tree -.predicates.a
predicates.a +.predicates.a
2022-12-01 00:51:43 +03:00
==
2023-01-05 21:17:42 +03:00
?: =((lent components.a) 4)
2022-12-01 00:51:43 +03:00
2023-01-05 21:17:42 +03:00
::$(components.a ~, working-tree +<.components.a)
%= ^$
components.a ~
working-tree -.predicates.a
predicates.a +.predicates.a
2022-12-01 00:51:43 +03:00
==
2023-01-05 21:17:42 +03:00
::$(components.a +>+>+.components.a, working-tree [+>+<.components.a +<.components.a +>+>-.components.a])
2022-12-01 00:51:43 +03:00
::%= $
2023-01-05 21:17:42 +03:00
:: components.a +>+>+.components.a
:: working-tree [+>+<.components.a +<.components.a +>+>-.components.a]
2022-12-01 00:51:43 +03:00
::==
!!
2023-01-05 21:17:42 +03:00
::$(components.a +>.components.a, working-tree [+>-.components.a +<.components.a +>+<.components.a])
2022-12-01 00:51:43 +03:00
!!
2023-01-05 21:17:42 +03:00
?: =(-.components.a %par) :: time to close out the nested tree
2022-09-30 23:31:56 +03:00
?: =(working-depth 0)
%= ^$
2023-01-05 21:17:42 +03:00
components.a +.components.a
2022-12-01 00:51:43 +03:00
resolved [%par [working-tree resolved]]
resolved-trees [working-tree resolved-trees]
working-tree ~
2022-09-30 23:31:56 +03:00
==
2022-09-27 20:07:16 +03:00
%= ^$
2023-01-05 21:17:42 +03:00
components.a +.components.a
2022-12-01 00:51:43 +03:00
resolved [%par [working-tree resolved]]
working-depth (sub working-depth 1)
resolved-trees [working-tree resolved-trees]
working-tree ~
2022-09-27 20:07:16 +03:00
==
2023-01-05 21:17:42 +03:00
::
:: below this point we deal with components only
?@ -.components.a
?: =(-.components.a %or) :: "or" the whole tree
?: =(%pal +<.components.a) :: new right is () enclosed tree
%= ^$
components.a +>+>.components.a
working-tree (next-working-tree [%or working-tree +>-.components.a])
2022-12-01 00:51:43 +03:00
==
%= $
2023-01-05 21:17:42 +03:00
components.a +>.components.a
working-tree (next-working-tree [%or working-tree +<.components.a])
2022-12-01 00:51:43 +03:00
==
2023-01-05 21:17:42 +03:00
:: working tree is an "or" and we are given an "and"; "and" the right tree
2022-12-01 00:51:43 +03:00
?: ?&(!=(working-tree ~) =(-.working-tree %or))
2023-01-05 21:17:42 +03:00
?: =(%pal +<.components.a) :: new right is () enclosed tree
%= ^$
components.a +>+.components.a
working-tree
(next-working-tree [%or +<.working-tree (next-working-tree [%and +>.working-tree +>-.components.a])])
2022-12-01 00:51:43 +03:00
==
2023-01-05 21:17:42 +03:00
%= ^$
components.a +>.components.a
working-tree
(next-working-tree [%or +<.working-tree (next-working-tree [%and +>.working-tree +<.components.a])])
2022-12-01 00:51:43 +03:00
==
2022-09-27 20:07:16 +03:00
:: working tree is an "and" and we are given an "and"
2022-09-30 23:31:56 +03:00
:: "and" the whole tree
:: new right is () enclosed tree
2023-01-05 21:17:42 +03:00
?: =(%pal +<.components.a)
%= ^$
components.a +>+>.components.a
working-tree (next-working-tree [%and working-tree +>-.components.a])
2022-12-01 00:51:43 +03:00
==
2023-01-05 21:17:42 +03:00
%= ^$
components.a +>.components.a
working-tree (next-working-tree [%and working-tree +<.components.a])
::working-tree
:: (next-working-tree [working-tree `(list raw-predicate-component)`+<.components.a predicates.a])
2022-12-01 00:51:43 +03:00
==
2023-01-05 21:17:42 +03:00
::
::
::~|('betting for now this never happens' !!)
2022-09-30 23:31:56 +03:00
:: can only be tree on first time
2023-01-05 21:17:42 +03:00
^$(components.a +.components.a, working-tree -.predicates.a)
++ next-working-tree
|= a=[conjunction=conjunction:ast working-tree=predicate:ast component=raw-predicate-component]
~| "working-tree: {<working-tree.a>}"
~| "component: {<component.a>}"
^- predicate:ast
?+ component.a ~|("next component unexpected type: {<component.a>}" !!)
qualified-column:ast [conjunction.a working-tree.a [`predicate-component:ast`component.a ~ ~]]
value-literal:ast [conjunction.a working-tree.a [`predicate-component:ast`component.a ~ ~]]
value-literal-list:ast [conjunction.a working-tree.a [`predicate-component:ast`component.a ~ ~]]
==
2022-12-01 00:51:43 +03:00
++ predicate-list
|= a=*
2023-01-05 21:17:42 +03:00
^- (list raw-predicate-component2)
=/ new-list=(list raw-predicate-component2) ~
2022-12-01 00:51:43 +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)
?: ?=(value-literal:ast -.a) $(new-list [i=`value-literal:ast`-.a t=new-list], a +.a)
?: ?=(value-literal-list:ast -.a) $(new-list [i=`value-literal-list:ast`-.a t=new-list], a +.a)
:: ?: ?=(aggregate:ast -.a) $(new-list [i=`aggregate:ast`-.a t=new-list], a +.a) :: to do
~|("problem with predicate noun: {<a>}" !!)
2022-10-23 23:12:24 +03:00
++ predicate-stop ~+ ;~ pose
2022-09-25 18:52:01 +03:00
;~(plug whitespace mic)
2022-10-05 23:00:47 +03:00
mic
2022-09-25 18:52:01 +03:00
;~(plug whitespace (jester 'where'))
;~(plug whitespace (jester 'select'))
;~(plug whitespace (jester 'as'))
;~(plug whitespace (jester 'join'))
;~(plug whitespace (jester 'left'))
;~(plug whitespace (jester 'right'))
;~(plug whitespace (jester 'outer'))
2022-10-05 23:00:47 +03:00
;~(plug whitespace (jester 'then'))
==
2022-10-23 23:12:24 +03:00
++ predicate-part ~+ ;~ pose
2023-01-11 02:26:55 +03:00
:: parse-aggregate
2022-12-01 00:51:43 +03:00
value-literal-list
;~(pose ;~(pfix whitespace parse-operator) parse-operator)
2022-10-05 23:00:47 +03:00
parse-datum
==
2023-01-05 21:17:42 +03:00
++ parse-predicate
2022-12-01 00:51:43 +03:00
(star ;~(less predicate-stop predicate-part))
2023-01-05 21:17:42 +03:00
++ produce-predicate
::
:: 1. resolve operators into trees
:: 2. determine deepest parenthesis nesting
:: 3. work from deepest nesting up to resolve conjunctions into trees
|= a=(list raw-predicate-component)
~& "raw-predicate2: {<a>}"
^- predicate:ast
=/ b=[@ud (list raw-predicate-component)] (resolve-depth (resolve-operators a))
=/ target-depth=@ud -.b
=/ working-list=(list raw-predicate-component) +.b
=/ parm=[(list raw-predicate-component) (list predicate:ast)] [working-list ~]
|-
?. (gth target-depth 0)
:: ~| "target-depth: {<target-depth>}"
:: ~| "-.parm: {<-.parm>}"
:: ~| "+.parm: {<+.parm>}"
::`predicate:ast`(snag 0 `(list predicate:ast)`+:(resolve-conjunctions [target-depth `(list raw-predicate-component)`-.parm `(list predicate:ast)`+.parm]))
::(snag 0 +:(resolve-conjunctions [target-depth -.parm +.parm]))
+<:(resolve-conjunctions [target-depth -.parm +.parm])
%= $
target-depth (sub target-depth 1)
parm (resolve-conjunctions [target-depth -.parm +.parm])
==
++ predicate-state-machine
|= parsed=(list raw-predicate-component2)
^- predicate:ast
=/ working-tree=predicate:ast ~
=/ tree-stack=(list predicate:ast) ~
2023-01-11 02:26:55 +03:00
~| "predicate-state-machine parsed: {<parsed>}"
2023-01-05 21:17:42 +03:00
|-
?: =((lent parsed) 0) working-tree
?- -.parsed
%pal :: push working predicate onto the stack
%= $
tree-stack [working-tree tree-stack]
working-tree ~
parsed +.parsed
==
%par :: pop the stack, updating next working tree
%= $
tree-stack +.tree-stack
working-tree
?~ ->-.tree-stack [-<.tree-stack working-tree ~]
[-<.tree-stack ->-.tree-stack working-tree]
parsed +.parsed
==
unary-operator:ast
?~ working-tree !!
?~ l.working-tree !!
?~ r.working-tree !!
!!
binary-operator:ast
?~ working-tree !!
?~ l.working-tree !!
?~ r.working-tree !!
!!
ternary-operator:ast
?~ working-tree !!
?~ l.working-tree !!
?~ r.working-tree !!
!!
conjunction:ast
?~ working-tree !!
?~ l.working-tree !!
?~ r.working-tree !!
!!
qualified-column:ast
?~ working-tree
?: ?=(binary-operator:ast +<.parsed)
%= $
working-tree [+<.parsed [-.parsed ~ ~] ~]
parsed +>.parsed
==
2023-01-11 02:26:55 +03:00
?: ?&(=(%not +<.parsed) =(%between +>-.parsed))
?: =(%and +>+>-.parsed)
%= $
working-tree
[%not [%between (predicate-state-machine ~[-.parsed %gte +>+<.parsed]) (predicate-state-machine ~[-.parsed %lte +>+>+<.parsed])] ~]
parsed +>+>+>.parsed
==
%= $
working-tree
[%not [%between (predicate-state-machine ~[-.parsed %gte +>+<.parsed]) (predicate-state-machine ~[-.parsed %lte +>+>-.parsed])] ~]
parsed +>+>+.parsed
==
2023-01-05 21:17:42 +03:00
!!
?~ l.working-tree
%= $
working-tree [-.working-tree [-.parsed ~ ~] ~]
parsed +.parsed
==
?~ r.working-tree
%= $
working-tree [-.working-tree +<.working-tree [-.parsed ~ ~]]
parsed +.parsed
==
~|("can't get here" !!)
value-literal:ast
?~ working-tree !!
?~ l.working-tree !!
?~ r.working-tree !!
!!
value-literal-list:ast
?~ working-tree !!
?~ l.working-tree !!
?~ r.working-tree !!
!!
==
2022-10-05 23:00:47 +03:00
::
:: parse scalar
::
++ get-datum ~+ ;~ pose
;~(sfix parse-qualified-column whitespace)
;~(sfix parse-value-literal whitespace)
2022-10-16 02:09:57 +03:00
;~(sfix parse-datum whitespace)
parse-datum
2022-10-05 23:00:47 +03:00
==
2022-12-01 00:51:43 +03:00
::++ cook-if
2022-10-16 02:09:57 +03:00
:: |= parsed=*
:: ^- if-then-else:ast
:: (if-then-else:ast %if-then-else -.parsed +>-.parsed +>+>-.parsed)
2022-10-13 18:51:22 +03:00
++ 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-10-05 23:00:47 +03:00
==
++ parse-when-then ;~ plug
2022-10-13 18:51:22 +03:00
;~(pfix whitespace (cold %when (jester 'when')))
;~(pose parse-predicate parse-datum)
;~(pfix whitespace (cold %then (jester 'then')))
2022-10-22 01:37:24 +03:00
;~(pose parse-aggregate scalar-body parse-datum)
2022-10-05 23:00:47 +03:00
==
++ parse-case-else ;~ plug
2022-10-13 18:51:22 +03:00
;~(pfix whitespace (cold %else (jester 'else')))
2022-10-22 01:37:24 +03:00
;~(pfix whitespace ;~(pose parse-aggregate scalar-body parse-datum))
2022-10-13 18:51:22 +03:00
;~(pfix whitespace (cold %end (jester 'end')))
2022-10-05 23:00:47 +03:00
==
++ cook-case
|= parsed=*
2022-10-23 23:12:24 +03:00
~+
2022-10-05 23:00:47 +03:00
=/ 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) ~)
?: ?=(value-literal:ast -.parsed)
?: =('else' +>-.parsed) (case:ast %case -.parsed (flop cases) +>+<.parsed)
(case:ast %case -.parsed (flop cases) ~)
2022-12-01 02:06:42 +03:00
~|("cannot parse case {<parsed>}" !!)
2022-10-05 23:00:47 +03:00
++ parse-case ;~ plug
parse-datum
(star parse-when-then)
2022-10-13 18:51:22 +03:00
;~(pose parse-case-else ;~(pfix whitespace (cold %end (jester 'end'))))
==
::++ 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
==
2022-10-21 20:44:14 +03:00
++ parse-coalesce ~+ (more com ;~(pose parse-aggregate get-datum))
2022-10-13 18:51:22 +03:00
++ parse-math ;~ plug
(cold %begin (jester 'begin'))
(star scalar-token)
==
2022-12-01 00:51:43 +03:00
++ parse-scalar-body %+ knee *noun
2022-10-13 18:51:22 +03:00
|. ~+
;~ pose
;~(plug (cold %if (jester 'if')) parse-if)
;~(plug (cold %case (jester 'case')) parse-case)
;~(plug (cold %coalesce (jester 'coalesce')) parse-coalesce)
parse-math
2022-10-05 23:00:47 +03:00
==
++ scalar-stop ;~ pose
;~(plug whitespace (jester 'where'))
;~(plug whitespace (jester 'scalar'))
2022-10-13 18:51:22 +03:00
;~(plug whitespace (jester 'select'))
2022-10-05 23:00:47 +03:00
==
++ scalar-body ;~(pfix whitespace parse-scalar-body)
2022-10-23 23:12:24 +03:00
++ parse-scalar-part ~+ ;~ plug
2022-12-01 00:51:43 +03:00
(cold %scalar ;~(pfix whitespace (jester 'scalar')))
2022-10-23 23:12:24 +03:00
parse-face
==
2022-10-05 23:00:47 +03:00
++ parse-scalar ;~ pose
2022-10-23 23:12:24 +03:00
;~(plug parse-scalar-part ;~(pfix ;~(plug whitespace (jester 'as')) scalar-body))
;~(plug parse-scalar-part scalar-body)
2022-10-13 18:51:22 +03:00
==
::
:: select
::
2022-10-24 23:08:56 +03:00
++ select-stop ;~ plug
2022-12-01 00:51:43 +03:00
whitespace
;~ pose
(jester 'top')
2022-10-24 23:08:56 +03:00
(jester 'bottom')
;~(plug (jester 'top') whitespace dem whitespace (jester 'bottom'))
==
2022-10-16 02:09:57 +03:00
==
2022-10-21 20:44:14 +03:00
++ parse-aggregate-column ~+ (stag %selected-aggregate parse-aggregate)
2022-10-23 23:12:24 +03:00
++ 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)))
2022-10-21 20:44:14 +03:00
++ parse-selection ~+ ;~ pose
;~(plug ;~(sfix parse-aggregate-column whitespace) (cold %as (jester 'as')) ;~(pfix whitespace alias))
parse-aggregate-column
2022-10-16 22:09:53 +03:00
parse-alias-all
parse-object-all
2022-10-17 01:40:25 +03:00
;~(plug ;~(sfix ;~(pose parse-qualified-column parse-value-literal) whitespace) (cold %as (jester 'as')) ;~(pfix whitespace alias))
2022-10-23 23:12:24 +03:00
;~(pose parse-qualified-column parse-value-literal)
2022-10-16 02:09:57 +03:00
(cold %all tar)
==
2022-10-24 01:05:57 +03:00
++ select-column :: ifix is faster here than pose pfix sfix whitespace
(ifix [whitespace whitespace] parse-selection)
2022-10-24 23:08:56 +03:00
++ select-columns ;~ pose
(full (more com select-column))
select-column
==
2022-10-23 23:12:24 +03:00
++ select-top-bottom-distinct ;~ plug
2022-10-13 18:51:22 +03:00
(cold %top ;~(plug whitespace (jester 'top')))
;~(pfix whitespace dem)
(cold %bottom ;~(plug whitespace (jester 'bottom')))
;~(pfix whitespace dem)
(cold %distinct ;~(plug whitespace (jester 'distinct')))
2022-10-16 02:09:57 +03:00
select-columns
2022-10-13 18:51:22 +03:00
==
2022-10-23 23:12:24 +03:00
++ select-top-bottom ;~ plug
2022-10-13 18:51:22 +03:00
(cold %top ;~(plug whitespace (jester 'top')))
;~(pfix whitespace dem)
(cold %bottom ;~(plug whitespace (jester 'bottom')))
;~(pfix whitespace dem)
2022-10-17 01:40:25 +03:00
select-columns
2022-10-13 18:51:22 +03:00
==
2022-10-23 23:12:24 +03:00
++ select-top-distinct ;~ plug
2022-10-13 18:51:22 +03:00
(cold %top ;~(plug whitespace (jester 'top')))
;~(pfix whitespace dem)
(cold %distinct ;~(plug whitespace (jester 'distinct')))
2022-10-16 02:09:57 +03:00
select-columns
2022-10-13 18:51:22 +03:00
==
2022-10-23 23:12:24 +03:00
++ select-top ;~ plug
2022-10-13 18:51:22 +03:00
(cold %top ;~(plug whitespace (jester 'top')))
2022-10-16 02:09:57 +03:00
;~(pfix whitespace dem)
2022-10-24 23:08:56 +03:00
;~(less ;~(plug whitespace (jester 'bottom')) select-columns)
2022-10-13 18:51:22 +03:00
==
2022-10-23 23:12:24 +03:00
++ select-bottom-distinct ;~ plug
2022-10-13 18:51:22 +03:00
(cold %bottom ;~(plug whitespace (jester 'bottom')))
;~(pfix whitespace dem)
(cold %distinct ;~(plug whitespace (jester 'distinct')))
2022-10-16 02:09:57 +03:00
select-columns
2022-10-13 18:51:22 +03:00
==
2022-10-23 23:12:24 +03:00
++ select-bottom ;~ plug
2022-10-13 18:51:22 +03:00
(cold %bottom ;~(plug whitespace (jester 'bottom')))
;~(pfix whitespace dem)
2022-10-17 01:40:25 +03:00
select-columns
2022-10-13 18:51:22 +03:00
==
2022-10-23 23:12:24 +03:00
++ select-distinct ;~ plug
2022-10-13 18:51:22 +03:00
(cold %distinct ;~(plug whitespace (jester 'distinct')))
2022-10-16 02:09:57 +03:00
select-columns
==
2022-10-23 23:12:24 +03:00
++ parse-select ;~ plug
2022-10-16 02:09:57 +03:00
(cold %select ;~(plug whitespace (jester 'select')))
2022-10-24 23:08:56 +03:00
;~ pose
select-top-bottom-distinct
select-top-bottom
select-top-distinct
select-top
select-bottom-distinct
select-bottom
select-distinct
;~(less select-stop select-columns)
2022-10-17 01:40:25 +03:00
==
2022-09-12 22:38:25 +03:00
==
2022-08-28 18:58:03 +03:00
::
2022-10-22 22:03:54 +03:00
:: group and order by
::
2022-10-24 23:08:56 +03:00
++ parse-grouping-column (ifix [whitespace whitespace] ;~(pose parse-qualified-column dem))
2022-10-22 22:03:54 +03:00
++ parse-group-by ;~ plug
(cold %group-by ;~(plug whitespace (jester 'group') whitespace (jester 'by')))
(more com parse-grouping-column)
==
++ 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
2022-10-24 01:05:57 +03:00
(ifix [whitespace whitespace] parse-ordered-column)
(cook cook-ordering-column (ifix [whitespace whitespace] ;~(pose parse-qualified-column dem)))
2022-10-22 22:03:54 +03:00
==
++ parse-order-by ;~ plug
(cold %order-by ;~(plug whitespace (jester 'order') whitespace (jester 'by')))
(more com parse-ordering-column)
==
2022-11-07 03:56:54 +03:00
::@@@@@@@@@@@@@@@@@@@@@@
2022-12-01 00:51:43 +03:00
::++ produce-joins
:: |= a=* ::(list *)
:: =/ joins=(list joined-object:ast) ~
:: ^- (list joined-object:ast)
:: |-
:: ?: =(a ~) (flop joins)
:: ?: ?=(joined-object:ast -.a) $(joins [-.a joins], a +.a)
2022-11-07 03:56:54 +03:00
::(crash "cannot produce join from {<-.a>}")
2022-12-01 00:51:43 +03:00
:: !!
::++ produce-from
:: |= a=* ::(list *)
:: ^- from:ast
:: ?: =(%query-object -<.a) ::?&(=(%query-object -<.a) (gth (lent a) 0))
:: ?: =(+.a ~) (from:ast %from -.a ~)
:: (from:ast -.a (produce-joins +.a))
2022-11-07 03:56:54 +03:00
::(crash "cannot produce query-object from {<-.a>}")
2022-12-01 00:51:43 +03:00
:: !!
2022-11-07 03:56:54 +03:00
::@@@@@@@@@@@@@@@@@@@@@@
2022-12-01 00:51:43 +03:00
++ produce-from
2022-11-07 03:56:54 +03:00
|= a=*
2022-12-01 00:51:43 +03:00
^- from:ast
2022-11-07 03:56:54 +03:00
?> ?=(query-object:ast -.a)
2022-12-01 00:51:43 +03:00
=/ query-object=query-object:ast -.a
=/ raw-joined-objects +.a
=/ joined-objects=(list joined-object:ast) ~
=/ is-cross-join=? %.n
|-
?: =(raw-joined-objects ~)
?: is-cross-join
?: =((lent joined-objects) 1)
2023-01-05 21:17:42 +03:00
(from:ast %from query-object (flop joined-objects))
~|("cross join must be only join in query" !!) :: to do, not sure this is required, investigate later
(from:ast %from query-object (flop joined-objects))
?> ?=(join-type:ast -<.raw-joined-objects)
?> ?=(query-object:ast ->-.raw-joined-objects)
?: ?=(%cross-join -<.raw-joined-objects)
2022-12-01 00:51:43 +03:00
%= $
2023-01-05 21:17:42 +03:00
joined-objects
[(joined-object:ast %joined-object %cross-join ->-.raw-joined-objects ~) joined-objects]
2022-12-01 00:51:43 +03:00
is-cross-join %.y
2023-01-05 21:17:42 +03:00
raw-joined-objects +.raw-joined-objects
2022-12-01 00:51:43 +03:00
==
2023-01-11 02:26:55 +03:00
=/ joined=joined-object:ast
(joined-object:ast %joined-object -<.raw-joined-objects ->-.raw-joined-objects `(predicate-state-machine (predicate-list ->+.raw-joined-objects)))
2022-12-01 00:51:43 +03:00
%= $
2023-01-05 21:17:42 +03:00
joined-objects [joined joined-objects]
raw-joined-objects +.raw-joined-objects
2022-12-01 00:51:43 +03:00
==
2022-11-07 03:56:54 +03:00
++ produce-select
|= a=*
^- select:ast
=/ top=(unit @ud) ~
=/ bottom=(unit @ud) ~
=/ distinct=? %.n
=/ columns=(list selected-column:ast) ~
2022-12-01 00:51:43 +03:00
~| "produce-select a: {<a>}"
2023-01-11 02:26:55 +03:00
?: ?=([%top @ %bottom @ %distinct %all ~] a)
2022-12-01 00:51:43 +03:00
?> ?=(selected-column:ast %all)
(select:ast %select `+<.a `+>+<.a ~ %.y ~[(selected-column:ast %all)])
2023-01-11 02:26:55 +03:00
?: ?=([%top @ %bottom @ %all ~] a)
2022-12-01 00:51:43 +03:00
?> ?=(selected-column:ast %all)
(select:ast %select `+<.a `+>+<.a ~ %.n ~[(selected-column:ast %all)])
2023-01-11 02:26:55 +03:00
?: ?=([%top @ %distinct %all ~] a)
2022-11-07 03:56:54 +03:00
?> ?=(selected-column:ast %all)
(select:ast %select `+<.a ~ %.y ~[(selected-column:ast %all)])
2023-01-11 02:26:55 +03:00
?: ?=([%top @ %all ~] a)
2022-12-01 00:51:43 +03:00
?> ?=(selected-column:ast %all)
(select:ast %select `+<.a ~ %.n ~[(selected-column:ast %all)])
2023-01-11 02:26:55 +03:00
?: ?=([%bottom @ %distinct %all ~] a)
2022-12-01 00:51:43 +03:00
?> ?=(selected-column:ast %all)
(select:ast %select ~ `+<.a %.y ~[(selected-column:ast %all)])
2023-01-11 02:26:55 +03:00
?: ?=([%bottom @ %all ~] a)
2022-12-01 00:51:43 +03:00
?> ?=(selected-column:ast %all)
(select:ast %select ~ `+<.a %.n ~[(selected-column:ast %all)])
2023-01-11 02:26:55 +03:00
?: ?=([%distinct %all ~] a)
2022-12-01 00:51:43 +03:00
?> ?=(selected-column:ast %all)
(select:ast %select ~ ~ %.y ~[(selected-column:ast %all)])
2023-01-11 02:26:55 +03:00
?: ?=([%all ~] a)
2022-12-01 00:51:43 +03:00
?> ?=(selected-column:ast %all)
(select:ast %select ~ ~ %.n ~[(selected-column:ast %all)])
2022-11-07 03:56:54 +03:00
:: |-
:: ?~ a (select:ast %select top bottom distinct columns)
:: ?: ?&(=(-.a %top) ?=(@ud +<.a)) $(a +>.a, top `+<.a)
:: ?: ?&(=(-.a %bottom) ?=(@ud +<.a)) $(a +>.a, bottom `+<.a)
:: ?: =(-.a %distinct) $(a +.a, distinct %.y)
:: ?: =(-.a %all) $(a ~, columns ~[(selected-column:ast %all)])
2022-12-01 02:06:42 +03:00
~|("cannot parse select {<a>}" !!)
2023-01-05 21:17:42 +03:00
++ build-simple-query
|= a=[from=(unit from:ast) scalars=(list scalar-function:ast) predicate=(unit predicate:ast) select=select:ast group-by=(unit group-by:ast) having=(unit having:ast) order-by=(unit order-by:ast)]
^- simple-query:ast
=/ priori=(unit priori:ast) ?: ?&(=(from.a ~) =(scalars.a ~) =(predicate.a ~)) ~
`(priori:ast %priori from.a scalars.a predicate.a)
=/ posteriori=(unit posteriori:ast) ?: ?&(=(group-by.a ~) =(having.a ~) =(order-by.a ~)) ~
`(posteriori:ast %posteriori group-by.a having.a order-by.a)
(simple-query:ast %simple-query priori select.a posteriori)
++ produce-simple-query
2022-11-07 03:56:54 +03:00
|= a=(list *)
^- simple-query:ast
=/ from=(unit from:ast) ~
=/ scalars=(list scalar-function:ast) ~
=/ predicate=(unit predicate:ast) ~
=/ select=(unit select:ast) ~
=/ group-by=(unit group-by:ast) ~
=/ having=(unit having:ast) ~
=/ order-by=(unit order-by:ast) ~
|-
2022-12-01 02:06:42 +03:00
?~ a ~|("cannot parse simple-query {<a>}" !!)
2023-01-11 02:26:55 +03:00
?: =(i.a %query) $(a t.a)
?: =(i.a %end-command) (build-simple-query [from scalars predicate (need select) group-by having order-by])
2022-11-07 03:56:54 +03:00
::?: =(i.a %scalars) $(a t.a, scalars +.i.a)
2023-01-11 02:26:55 +03:00
?: =(-<.a %scalars) $(a t.a, scalars ~)
?: =(-<.a %where) $(a t.a, predicate `(predicate-state-machine (predicate-list +.i.a)))
?: =(-<.a %select) $(a t.a, select `(produce-select +.i.a))
?: =(-<.a %group-by) $(a t.a, group-by ~)
?: =(-<.a %having) $(a t.a, having ~)
?: =(-<.a %order-by) $(a t.a, order-by ~)
?: =(-<-.a %query-object) $(a t.a, from `(produce-from i.a))
2022-12-01 02:06:42 +03:00
~|("cannot parse simple-query {<a>}" !!)
2022-11-07 03:56:54 +03:00
::
2022-08-28 18:58:03 +03:00
:: parse urQL command
::
2022-09-07 22:25:00 +03:00
++ parse-alter-index
2022-09-08 23:48:02 +03:00
=/ columns ;~(pfix whitespace ordered-column-list)
2022-09-07 22:25:00 +03:00
=/ 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
2022-09-07 23:50:04 +03:00
(cook |=(a=* (qualified-namespace [a current-database])) parse-qualified-2-name)
;~(pfix ;~(plug whitespace (jester 'transfer')) ;~(pfix whitespace ;~(pose (jester 'table') (jester 'view'))))
2022-09-07 22:25:00 +03:00
;~(sfix ;~(pfix whitespace parse-qualified-3object) end-or-next-command)
==
2022-09-08 23:48:02 +03:00
++ 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)
==
2022-08-28 18:58:03 +03:00
++ parse-create-namespace ;~ sfix
parse-qualified-2-name
end-or-next-command
==
2022-09-07 01:46:28 +03:00
++ parse-create-index
=/ is-unique ~+ ;~(pfix whitespace (jester 'unique'))
=/ index-name ~+ ;~(pfix whitespace (jester 'index') parse-face)
=/ type-and-name ;~ pose
;~(plug is-unique clustering index-name)
;~(plug is-unique index-name)
;~(plug clustering index-name)
index-name
2022-12-01 00:51:43 +03:00
==
;~ plug
type-and-name
;~(pfix whitespace ;~(pfix (jester 'on') ;~(pfix whitespace parse-qualified-3object)))
;~(sfix ordered-column-list end-or-next-command)
==
2022-09-07 01:46:28 +03:00
++ parse-create-table ;~ plug
;~(pfix whitespace parse-qualified-3object)
2022-09-08 23:48:02 +03:00
column-definitions
2022-09-10 02:30:41 +03:00
;~(sfix ;~(pose ;~(plug primary-key ;~(pfix foreign-key-literal (more com full-foreign-key))) primary-key) end-or-next-command)
2022-09-07 01:46:28 +03:00
==
2022-08-28 18:58:03 +03:00
++ parse-drop-database ;~ sfix
;~(pose ;~(plug ;~(pfix whitespace (jester 'force')) ;~(pfix whitespace sym)) ;~(pfix whitespace sym))
end-or-next-command
==
2022-08-28 18:58:03 +03:00
++ parse-drop-index ;~ sfix
;~(pfix whitespace ;~(plug parse-face ;~(pfix whitespace ;~(pfix (jester 'on') ;~(pfix whitespace parse-qualified-3object)))))
end-or-next-command
==
2022-08-28 18:58:03 +03:00
++ parse-drop-namespace ;~ sfix
;~(pose ;~(plug ;~(pfix whitespace (cold %force (jester 'force'))) parse-qualified-2-name) parse-qualified-2-name)
end-or-next-command
==
2022-08-28 18:58:03 +03:00
++ drop-table-or-view ;~ sfix
;~(pose ;~(pfix whitespace ;~(plug (jester 'force') parse-qualified-3object)) parse-qualified-3object)
end-or-next-command
==
2022-08-28 18:58:03 +03:00
++ 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)
==
2022-12-01 00:51:43 +03:00
++ parse-insert ;~ plug
2022-09-12 22:38:25 +03:00
;~(pfix whitespace parse-qualified-object)
;~(pose ;~(plug face-list ;~(pfix whitespace (jester 'values'))) ;~(pfix whitespace (jester 'values')))
2022-10-05 23:00:47 +03:00
;~(pfix whitespace (more whitespace (ifix [pal par] (more com parse-insert-value))))
2022-09-12 22:38:25 +03:00
end-or-next-command
==
2023-01-11 02:26:55 +03:00
++ parse-query1 ;~ plug
2022-09-25 18:52:01 +03:00
parse-object-and-joins
2022-12-01 00:51:43 +03:00
:: (stag %scalars (star parse-scalar))
2023-01-11 02:26:55 +03:00
;~(pfix whitespace ;~(plug (cold %where (jester 'where')) parse-predicate))
2022-10-24 01:05:57 +03:00
parse-select
2022-12-01 00:51:43 +03:00
:: parse-group-by
:: parse-order-by
2022-09-12 22:38:25 +03:00
end-or-next-command
==
2023-01-11 02:26:55 +03:00
++ parse-query2 ;~ plug
parse-object-and-joins
:: (stag %scalars (star parse-scalar))
parse-select
:: parse-group-by
:: parse-order-by
end-or-next-command
==
++ parse-query ;~ pose
parse-query1
parse-query2
==
2022-08-28 18:58:03 +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)
==
2022-08-28 18:58:03 +03:00
++ parse-truncate-table ;~ sfix
;~(pfix whitespace parse-qualified-object)
end-or-next-command
==
2022-08-28 18:58:03 +03:00
::
:: parse urQL script
::
++ parse
|= script=tape
^- (list command-ast)
=/ commands `(list command-ast)`~
=/ script-position [1 1]
=/ parse-command ;~ pose
2022-09-07 22:25:00 +03:00
(cold %alter-index ;~(plug whitespace (jester 'alter') whitespace (jester 'index')))
2022-09-07 23:50:04 +03:00
(cold %alter-namespace ;~(plug whitespace (jester 'alter') whitespace (jester 'namespace')))
2022-09-08 23:48:02 +03:00
(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')))
2022-09-07 01:46:28 +03:00
(cold %create-index ;~(plug whitespace (jester 'create'))) :: must be last of creates
(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')))
2022-09-04 20:53:13 +03:00
(cold %insert ;~(plug whitespace (jester 'insert') whitespace (jester 'into')))
2022-09-12 22:38:25 +03:00
(cold %query ;~(plug whitespace (jester 'from')))
2023-01-11 02:26:55 +03:00
::(cold %query ;~(plug whitespace (jester 'select')))
::(cold %query ;~(plug whitespace select-rule))
(cold %revoke ;~(plug whitespace (jester 'revoke')))
(cold %truncate-table ;~(plug whitespace (jester 'truncate') whitespace (jester 'table')))
==
2023-01-05 21:17:42 +03:00
=/ dummy ~|('Current database name is not a proper term' (scan (trip current-database) sym))
2022-08-13 05:13:25 +03:00
:: main loop
2022-08-12 21:08:20 +03:00
::
2022-08-06 17:06:18 +03:00
|-
2022-08-12 21:08:20 +03:00
?: =(~ script) :: https://github.com/urbit/arvo/issues/1024
2022-08-13 05:00:44 +03:00
(flop commands)
2022-09-02 03:14:57 +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)
2022-08-13 05:00:44 +03:00
=/ command-nail u.+3:q.+3:(parse-command [script-position script])
2022-08-12 21:08:20 +03:00
?- `command`p.command-nail
2022-09-07 22:25:00 +03:00
%alter-index
=/ index-nail (parse-alter-index [[1 1] q.q.command-nail])
=/ parsed (wonk index-nail)
2022-12-01 00:51:43 +03:00
=/ next-cursor
2022-09-07 22:25:00 +03:00
(get-next-cursor [script-position +<.command-nail p.q.u.+3:q.+3:index-nail])
2022-09-08 23:48:02 +03:00
?: ?=([[@ @ @ @ @] [@ @ @ @ @] @] [parsed]) ::"alter index action"
2022-12-01 00:51:43 +03:00
%= $
2022-09-08 23:48:02 +03:00
script q.q.u.+3.q:index-nail
script-position next-cursor
2022-12-01 00:51:43 +03:00
commands
2022-09-08 23:48:02 +03:00
[`command-ast`(alter-index:ast %alter-index -.parsed +<.parsed ~ +>.parsed) commands]
==
?: ?=([[@ @ @ @ @] [@ @ @ @ @] [[@ @ @] %~]] [parsed]) ::"alter index single column"
2022-12-01 00:51:43 +03:00
%= $
2022-09-08 23:48:02 +03:00
script q.q.u.+3.q:index-nail
script-position next-cursor
2022-12-01 00:51:43 +03:00
commands
2022-09-08 23:48:02 +03:00
[`command-ast`(alter-index:ast %alter-index -.parsed +<.parsed +>.parsed %rebuild) commands]
==
2022-09-07 22:25:00 +03:00
?: ?=([[@ @ @ @ @] [@ @ @ @ @] * @] [parsed]) ::"alter index columns action"
2022-12-01 00:51:43 +03:00
%= $
2022-09-07 22:25:00 +03:00
script q.q.u.+3.q:index-nail
script-position next-cursor
2022-12-01 00:51:43 +03:00
commands
2022-09-07 22:25:00 +03:00
[`command-ast`(alter-index:ast %alter-index -.parsed +<.parsed +>-.parsed +>+.parsed) commands]
==
2022-09-08 23:48:02 +03:00
?: ?=([[@ @ @ @ @] [@ @ @ @ @] *] [parsed]) ::"alter index multiple columns"
2022-12-01 00:51:43 +03:00
%= $
2022-09-07 22:25:00 +03:00
script q.q.u.+3.q:index-nail
script-position next-cursor
2022-12-01 00:51:43 +03:00
commands
2022-09-07 22:25:00 +03:00
[`command-ast`(alter-index:ast %alter-index -.parsed +<.parsed +>.parsed %rebuild) commands]
2022-12-01 00:51:43 +03:00
==
2022-12-01 02:06:42 +03:00
~|("Cannot parse alter-index {<p.q.command-nail>}" !!)
2022-09-07 22:25:00 +03:00
%alter-namespace
=/ namespace-nail (parse-alter-namespace [[1 1] q.q.command-nail])
=/ parsed (wonk namespace-nail)
2022-12-01 00:51:43 +03:00
=/ next-cursor
2022-09-07 22:25:00 +03:00
(get-next-cursor [script-position +<.command-nail p.q.u.+3:q.+3:namespace-nail])
2022-12-01 00:51:43 +03:00
%= $
2022-09-07 23:50:04 +03:00
script q.q.u.+3.q:namespace-nail
script-position next-cursor
2022-12-01 00:51:43 +03:00
commands
2022-09-07 23:50:04 +03:00
[`command-ast`(alter-namespace:ast %alter-namespace -<.parsed ->.parsed +<.parsed +>+>+<.parsed +>+>+>.parsed) commands]
==
2022-09-08 23:48:02 +03:00
%alter-table
=/ table-nail (parse-alter-table [[1 1] q.q.command-nail])
=/ parsed (wonk table-nail)
2022-12-01 00:51:43 +03:00
=/ next-cursor
2022-09-08 23:48:02 +03:00
(get-next-cursor [script-position +<.command-nail p.q.u.+3:q.+3:table-nail])
?: =(+<.parsed %alter-column)
2022-12-01 00:51:43 +03:00
%= $
2022-09-08 23:48:02 +03:00
script q.q.u.+3.q:table-nail
script-position next-cursor
2022-12-01 00:51:43 +03:00
commands
2022-09-08 23:48:02 +03:00
[`command-ast`(alter-table:ast %alter-table -.parsed +>.parsed ~ ~ ~ ~) commands]
==
?: =(+<.parsed %add-column)
2022-12-01 00:51:43 +03:00
%= $
2022-09-08 23:48:02 +03:00
script q.q.u.+3.q:table-nail
script-position next-cursor
2022-12-01 00:51:43 +03:00
commands
2022-09-08 23:48:02 +03:00
[`command-ast`(alter-table:ast %alter-table -.parsed ~ +>.parsed ~ ~ ~) commands]
==
?: =(+<.parsed %drop-column)
2022-12-01 00:51:43 +03:00
%= $
2022-09-08 23:48:02 +03:00
script q.q.u.+3.q:table-nail
script-position next-cursor
2022-12-01 00:51:43 +03:00
commands
2022-09-08 23:48:02 +03:00
[`command-ast`(alter-table:ast %alter-table -.parsed ~ ~ +>.parsed ~ ~) commands]
==
?: =(+<.parsed %add-fk)
2022-12-01 00:51:43 +03:00
%= $
2022-09-08 23:48:02 +03:00
script q.q.u.+3.q:table-nail
script-position next-cursor
2022-12-01 00:51:43 +03:00
commands
2022-09-10 02:30:41 +03:00
[`command-ast`(alter-table:ast %alter-table -.parsed ~ ~ ~ (build-foreign-keys [-.parsed +>.parsed]) ~) commands]
2022-12-01 00:51:43 +03:00
==
2022-09-08 23:48:02 +03:00
?: =(+<.parsed %drop-fk)
2022-12-01 00:51:43 +03:00
%= $
2022-09-08 23:48:02 +03:00
script q.q.u.+3.q:table-nail
script-position next-cursor
2022-12-01 00:51:43 +03:00
commands
2022-09-10 20:02:00 +03:00
[`command-ast`(alter-table:ast %alter-table -.parsed ~ ~ ~ ~ +>.parsed) commands]
2022-12-01 00:51:43 +03:00
==
2022-12-01 02:06:42 +03:00
~|("Cannot parse table {<p.q.command-nail>}" !!)
2022-08-12 21:08:20 +03:00
%create-database
2022-08-14 00:20:30 +03:00
~| 'Create database must be only statement in script'
2022-12-01 00:51:43 +03:00
?> =((lent commands) 0)
%= $
2022-08-16 22:18:14 +03:00
script ""
2022-12-01 00:51:43 +03:00
commands
2022-08-16 22:18:14 +03:00
[`command-ast`(create-database:ast %create-database p.u.+3:q.+3:(parse-face [[1 1] q.q.command-nail])) commands]
2022-08-14 00:20:30 +03:00
==
2022-08-12 21:08:20 +03:00
%create-index
2022-09-07 01:46:28 +03:00
=/ index-nail (parse-create-index [[1 1] q.q.command-nail])
=/ parsed (wonk index-nail)
2022-12-01 00:51:43 +03:00
=/ next-cursor
2022-09-07 22:25:00 +03:00
(get-next-cursor [script-position +<.command-nail p.q.u.+3:q.+3:index-nail])
?: ?=([@ [* *]] [parsed]) ::"create index ..."
2022-12-01 00:51:43 +03:00
%= $
script q.q.u.+3.q:index-nail
script-position next-cursor
2022-12-01 00:51:43 +03:00
commands
[`command-ast`(create-index:ast %create-index -.parsed +<.parsed %.n %.n +>.parsed) commands]
==
2022-12-01 00:51:43 +03:00
?: ?=([[@ @] [* *]] [parsed])
?: =(-<.parsed %unique) ::"create unique index ..."
2022-12-01 00:51:43 +03:00
%= $
script q.q.u.+3.q:index-nail
script-position next-cursor
2022-12-01 00:51:43 +03:00
commands
[`command-ast`(create-index:ast %create-index ->.parsed +<.parsed %.y %.n +>.parsed) commands]
==
?: =(-<.parsed %clustered) ::"create clustered index ..."
2022-12-01 00:51:43 +03:00
%= $
script q.q.u.+3.q:index-nail
script-position next-cursor
2022-12-01 00:51:43 +03:00
commands
[`command-ast`(create-index:ast %create-index ->.parsed +<.parsed %.n %.y +>.parsed) commands]
==
?: =(-<.parsed %nonclustered) ::"create nonclustered index ..."
2022-12-01 00:51:43 +03:00
%= $
script q.q.u.+3.q:index-nail
script-position next-cursor
2022-12-01 00:51:43 +03:00
commands
[`command-ast`(create-index:ast %create-index ->.parsed +<.parsed %.n %.n +>.parsed) commands]
==
2022-12-01 02:06:42 +03:00
~|("Cannot parse index {<p.q.command-nail>}" !!)
?: ?=([[@ @ @] [* *]] [parsed])
?: =(->-.parsed %clustered) ::"create unique clustered index ..."
2022-12-01 00:51:43 +03:00
%= $
script q.q.u.+3.q:index-nail
script-position next-cursor
2022-12-01 00:51:43 +03:00
commands
[`command-ast`(create-index:ast %create-index ->+.parsed +<.parsed %.y %.y +>.parsed) commands]
==
?: =(->-.parsed %nonclustered) ::"create unique nonclustered index ..."
2022-12-01 00:51:43 +03:00
%= $
script q.q.u.+3.q:index-nail
script-position next-cursor
2022-12-01 00:51:43 +03:00
commands
[`command-ast`(create-index:ast %create-index ->+.parsed +<.parsed %.y %.n +>.parsed) commands]
==
2022-12-01 02:06:42 +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
2022-08-28 18:58:03 +03:00
=/ create-namespace-nail (parse-create-namespace [[1 1] q.q.command-nail])
2022-08-17 20:10:50 +03:00
=/ parsed (wonk create-namespace-nail)
2022-12-01 00:51:43 +03:00
=/ next-cursor
2022-08-22 00:09:24 +03:00
(get-next-cursor [script-position +<.command-nail p.q.u.+3:q.+3:create-namespace-nail])
2022-08-17 19:26:46 +03:00
?@ parsed
2022-12-01 00:51:43 +03:00
%= $
2022-08-17 19:26:46 +03:00
script q.q.u.+3.q:create-namespace-nail
script-position next-cursor
commands [`command-ast`(create-namespace:ast %create-namespace current-database parsed) commands]
2022-08-13 05:00:44 +03:00
==
2022-12-01 00:51:43 +03:00
%= $
2022-08-17 19:26:46 +03:00
script q.q.u.+3.q:create-namespace-nail
script-position next-cursor
commands [`command-ast`(create-namespace:ast %create-namespace -.parsed +.parsed) commands]
2022-08-13 05:00:44 +03:00
==
2022-08-12 21:08:20 +03:00
%create-table
2022-09-07 01:46:28 +03:00
=/ table-nail (parse-create-table [[1 1] q.q.command-nail])
2022-08-25 22:21:07 +03:00
=/ parsed (wonk table-nail)
2022-12-01 00:51:43 +03:00
=/ next-cursor
2022-09-07 22:25:00 +03:00
(get-next-cursor [script-position +<.command-nail p.q.u.+3:q.+3:table-nail])
2022-12-01 00:51:43 +03:00
?: ?=([* * [@ @ *]] parsed)
2022-09-10 02:30:41 +03:00
%= $ :: no foreign keys
script q.q.u.+3.q:table-nail
script-position next-cursor
2022-12-01 00:51:43 +03:00
commands
2022-09-10 02:30:41 +03:00
[`command-ast`(create-table:ast %create-table -.parsed +<.parsed (create-primary-key [-.parsed +>.parsed]) ~) commands]
==
2022-09-02 03:14:57 +03:00
%= $
script q.q.u.+3.q:table-nail
script-position next-cursor
2022-12-01 00:51:43 +03:00
commands
2022-09-10 02:30:41 +03:00
[`command-ast`(create-table:ast %create-table -.parsed +<.parsed (create-primary-key [-.parsed +>-.parsed]) (build-foreign-keys [-.parsed +>+.parsed])) commands]
2022-09-02 03:14:57 +03:00
==
2022-08-12 21:08:20 +03:00
%create-view
!!
2022-08-16 22:18:14 +03:00
%drop-database
2022-08-22 01:01:22 +03:00
=/ drop-database-nail (parse-drop-database [[1 1] q.q.command-nail])
=/ parsed (wonk drop-database-nail)
2022-12-01 00:51:43 +03:00
=/ next-cursor
2022-08-22 01:01:22 +03:00
(get-next-cursor [script-position +<.command-nail p.q.u.+3:q.+3:drop-database-nail])
?@ parsed :: name
2022-12-01 00:51:43 +03:00
%= $
2022-08-22 01:01:22 +03:00
script q.q.u.+3.q:drop-database-nail
script-position next-cursor
commands [`command-ast`(drop-database:ast %drop-database parsed %.n) commands]
==
?: ?=([@ @] parsed) :: force name
2022-12-01 00:51:43 +03:00
%= $
2022-08-22 01:01:22 +03:00
script q.q.u.+3.q:drop-database-nail
script-position next-cursor
commands [`command-ast`(drop-database:ast %drop-database +.parsed %.y) commands]
==
2022-12-01 02:06:42 +03:00
::~|("Cannot parse drop-database {<parsed>}" !!)
2022-08-16 22:18:14 +03:00
!!
%drop-index
2022-08-22 06:25:18 +03:00
=/ drop-index-nail (parse-drop-index [[1 1] q.q.command-nail])
=/ parsed (wonk drop-index-nail)
2022-12-01 00:51:43 +03:00
=/ next-cursor
2022-08-22 06:25:18 +03:00
(get-next-cursor [script-position +<.command-nail p.q.u.+3:q.+3:drop-index-nail])
2022-12-01 00:51:43 +03:00
%= $
2022-08-22 06:25:18 +03:00
script q.q.u.+3.q:drop-index-nail
script-position next-cursor
commands [`command-ast`(drop-index:ast %drop-index -.parsed +.parsed) commands]
==
2022-08-16 22:18:14 +03:00
%drop-namespace
2022-08-21 22:12:55 +03:00
=/ drop-namespace-nail (parse-drop-namespace [[1 1] q.q.command-nail])
=/ parsed (wonk drop-namespace-nail)
2022-12-01 00:51:43 +03:00
=/ next-cursor
2022-08-22 00:09:24 +03:00
(get-next-cursor [script-position +<.command-nail p.q.u.+3:q.+3:drop-namespace-nail])
?@ parsed :: name
2022-12-01 00:51:43 +03:00
%= $
2022-08-21 22:12:55 +03:00
script q.q.u.+3.q:drop-namespace-nail
script-position next-cursor
commands [`command-ast`(drop-namespace:ast %drop-namespace current-database parsed %.n) commands]
==
2022-08-22 00:09:24 +03:00
?: ?=([@ @] parsed) :: force name
2022-12-01 00:51:43 +03:00
?: =(%force -.parsed)
%= $
2022-08-22 00:09:24 +03:00
script q.q.u.+3.q:drop-namespace-nail
script-position next-cursor
commands [`command-ast`(drop-namespace:ast %drop-namespace current-database +.parsed %.y) commands]
==
2022-12-01 00:51:43 +03:00
%= $ :: db.name
2022-08-21 22:12:55 +03:00
script q.q.u.+3.q:drop-namespace-nail
script-position next-cursor
commands [`command-ast`(drop-namespace:ast %drop-namespace -.parsed +.parsed %.n) commands]
==
2022-08-22 00:09:24 +03:00
?: ?=([* [@ @]] parsed) :: force db.name
2022-12-01 00:51:43 +03:00
%= $
2022-08-21 22:12:55 +03:00
script q.q.u.+3.q:drop-namespace-nail
script-position next-cursor
commands [`command-ast`(drop-namespace:ast %drop-namespace +<.parsed +>.parsed %.y) commands]
==
2022-12-01 02:06:42 +03:00
::~|("Cannot parse drop-namespace {<parsed>}" !!)
2022-08-16 22:18:14 +03:00
!!
%drop-table
2022-08-28 18:58:03 +03:00
=/ drop-table-nail (drop-table-or-view [[1 1] q.q.command-nail])
2022-08-17 20:10:50 +03:00
=/ parsed (wonk drop-table-nail)
2022-12-01 00:51:43 +03:00
=/ next-cursor
2022-08-22 00:09:24 +03:00
(get-next-cursor [script-position +<.command-nail p.q.u.+3:q.+3:drop-table-nail])
2022-08-22 04:03:52 +03:00
?: ?=([@ @ @ @ @ @] parsed) :: force qualified table name
2022-08-17 19:35:12 +03:00
%= $
script q.q.u.+3.q:drop-table-nail
script-position next-cursor
2022-12-01 00:51:43 +03:00
commands
2022-08-22 04:03:52 +03:00
[`command-ast`(drop-table:ast %drop-table +.parsed %.y) commands]
2022-08-17 19:35:12 +03:00
==
2022-08-22 04:03:52 +03:00
?: ?=([@ @ @ @ @] parsed) :: qualified table name
2022-08-17 19:35:12 +03:00
%= $
script q.q.u.+3.q:drop-table-nail
script-position next-cursor
2022-12-01 00:51:43 +03:00
commands
2022-08-22 04:03:52 +03:00
[`command-ast`(drop-table:ast %drop-table parsed %.n) commands]
2022-08-17 19:35:12 +03:00
==
2022-12-01 02:06:42 +03:00
~|("Cannot parse drop-table {<parsed>}" !!)
2022-08-16 22:18:14 +03:00
%drop-view
2022-08-28 18:58:03 +03:00
=/ drop-view-nail (drop-table-or-view [[1 1] q.q.command-nail])
2022-08-17 20:10:50 +03:00
=/ parsed (wonk drop-view-nail)
2022-12-01 00:51:43 +03:00
=/ next-cursor
2022-08-22 00:09:24 +03:00
(get-next-cursor [script-position +<.command-nail p.q.u.+3:q.+3:drop-view-nail])
2022-08-22 04:03:52 +03:00
?: ?=([@ @ @ @ @ @] parsed) :: force qualified view
2022-08-16 22:18:14 +03:00
%= $
script q.q.u.+3.q:drop-view-nail
script-position next-cursor
2022-12-01 00:51:43 +03:00
commands
2022-08-22 04:03:52 +03:00
[`command-ast`(drop-view:ast %drop-view +.parsed %.y) commands]
2022-08-16 22:18:14 +03:00
==
2022-08-22 04:03:52 +03:00
?: ?=([@ @ @ @ @] parsed) :: qualified view
2022-08-16 22:18:14 +03:00
%= $
script q.q.u.+3.q:drop-view-nail
script-position next-cursor
2022-12-01 00:51:43 +03:00
commands
2022-08-22 04:03:52 +03:00
[`command-ast`(drop-view:ast %drop-view parsed %.n) commands]
2022-08-16 22:18:14 +03:00
==
2022-12-01 02:06:42 +03:00
~|("Cannot parse drop-view {<parsed>}" !!)
2022-08-23 03:53:59 +03:00
%grant
=/ grant-nail (parse-grant [[1 1] q.q.command-nail])
=/ parsed (wonk grant-nail)
2022-12-01 00:51:43 +03:00
=/ next-cursor
2022-08-23 03:53:59 +03:00
(get-next-cursor [script-position +<.command-nail p.q.u.+3:q.+3:grant-nail])
2022-08-24 02:30:27 +03:00
?: ?=([@ [@ [@ %~]] [@ @]] [parsed]) ::"grant adminread to ~sampel-palnet on database db"
2022-12-01 00:51:43 +03:00
%= $
2022-08-23 03:53:59 +03:00
script q.q.u.+3.q:grant-nail
script-position next-cursor
2022-12-01 00:51:43 +03:00
commands
2022-08-24 02:30:27 +03:00
[`command-ast`(grant:ast %grant -.parsed +<+.parsed +>.parsed) commands]
2022-08-23 03:53:59 +03:00
==
?: ?=([@ @ [@ @]] [parsed]) ::"grant adminread to parent on database db"
2022-12-01 00:51:43 +03:00
%= $
2022-08-23 03:53:59 +03:00
script q.q.u.+3.q:grant-nail
script-position next-cursor
2022-12-01 00:51:43 +03:00
commands
2022-08-23 03:53:59 +03:00
[`command-ast`(grant:ast %grant -.parsed +<.parsed +>.parsed) commands]
==
2022-08-24 02:30:27 +03:00
?: ?=([@ [@ [@ *]] [@ *]] [parsed]) ::"grant Readwrite to ~zod,~bus,~nec,~sampel-palnet on namespace db.ns"
2022-12-01 00:51:43 +03:00
%= $ ::"grant adminread to ~zod,~bus,~nec,~sampel-palnet on namespace ns" (ns previously cooked)
2022-08-24 02:30:27 +03:00
script q.q.u.+3.q:grant-nail ::"grant Readwrite to ~zod,~bus,~nec,~sampel-palnet on db.ns.table"
2022-08-23 03:53:59 +03:00
script-position next-cursor
2022-12-01 00:51:43 +03:00
commands
2022-08-24 02:30:27 +03:00
[`command-ast`(grant:ast %grant -.parsed +<+.parsed +>.parsed) commands]
2022-08-23 03:53:59 +03:00
==
2022-08-23 18:59:52 +03:00
?: ?=([@ @ [@ [@ *]]] [parsed]) ::"grant readonly to siblings on namespace db.ns"
2022-12-01 00:51:43 +03:00
%= $ ::"grant readwrite to moons on namespace ns" (ns previously cooked)
2022-08-23 03:53:59 +03:00
script q.q.u.+3.q:grant-nail
script-position next-cursor
2022-12-01 00:51:43 +03:00
commands
2022-08-23 03:53:59 +03:00
[`command-ast`(grant:ast %grant -.parsed +<.parsed +>.parsed) commands]
==
2022-12-01 02:06:42 +03:00
~|("Cannot parse grant {<parsed>}" !!)
2022-09-04 20:53:13 +03:00
%insert
=/ insert-nail (parse-insert [[1 1] q.q.command-nail])
=/ parsed (wonk insert-nail)
2022-12-01 00:51:43 +03:00
=/ next-cursor
2022-09-04 20:53:13 +03:00
(get-next-cursor [script-position +<.command-nail p.q.u.+3:q.+3:insert-nail])
2022-09-05 20:26:35 +03:00
?: ?=([[@ @ @ @ @] @ *] [parsed]) ::"insert rows"
2022-12-01 00:51:43 +03:00
%= $
2022-09-05 20:26:35 +03:00
script q.q.u.+3.q:insert-nail
script-position next-cursor
2022-12-01 00:51:43 +03:00
commands
2022-10-05 23:00:47 +03:00
[`command-ast`(insert:ast %insert -.parsed ~ (insert-values:ast %data +>-.parsed)) commands]
2022-09-05 20:26:35 +03:00
==
?: ?=([[@ @ @ @ @] [* @] *] [parsed]) ::"insert column names rows"
2022-12-01 00:51:43 +03:00
%= $
2022-09-05 20:26:35 +03:00
script q.q.u.+3.q:insert-nail
script-position next-cursor
2022-12-01 00:51:43 +03:00
commands
2022-10-05 23:00:47 +03:00
[`command-ast`(insert:ast %insert -.parsed `+<-.parsed (insert-values:ast %data +>-.parsed)) commands]
2022-09-05 20:26:35 +03:00
==
2022-12-01 02:06:42 +03:00
~|("Cannot parse insert {<parsed>}" !!)
2022-09-12 22:38:25 +03:00
%query
2022-12-01 00:51:43 +03:00
~| "Cannot parse query {<p.q.command-nail>}"
~| "q.q.command-nail: {<q.q.command-nail>}"
2022-09-12 22:38:25 +03:00
=/ query-nail (parse-query [[1 1] q.q.command-nail])
=/ parsed (wonk query-nail)
2022-12-01 00:51:43 +03:00
=/ next-cursor
2022-09-12 22:38:25 +03:00
(get-next-cursor [script-position +<.command-nail p.q.u.+3:q.+3:query-nail])
2022-10-24 23:08:56 +03:00
~| "parsed: {<parsed>}"
~| "remainder: {<q.q.u.+3:q.+3.query-nail>}"
2023-01-05 21:17:42 +03:00
%= $
script q.q.u.+3.q:query-nail
script-position next-cursor
commands
2023-01-11 02:26:55 +03:00
[`command-ast`(produce-simple-query parsed) commands]
2023-01-05 21:17:42 +03:00
==
2022-08-23 18:59:52 +03:00
%revoke
2022-12-01 02:06:42 +03:00
2022-08-23 18:59:52 +03:00
=/ revoke-nail (parse-revoke [[1 1] q.q.command-nail])
=/ parsed (wonk revoke-nail)
2022-12-01 00:51:43 +03:00
=/ next-cursor
2022-08-23 18:59:52 +03:00
(get-next-cursor [script-position +<.command-nail p.q.u.+3:q.+3:revoke-nail])
2022-08-24 02:30:27 +03:00
?: ?=([@ [@ [@ %~]] [@ @]] [parsed]) ::"revoke adminread from ~sampel-palnet on database db"
2022-12-01 00:51:43 +03:00
%= $
2022-08-23 18:59:52 +03:00
script q.q.u.+3.q:revoke-nail
script-position next-cursor
2022-12-01 00:51:43 +03:00
commands
2022-08-24 02:30:27 +03:00
[`command-ast`(revoke:ast %revoke -.parsed +<+.parsed +>.parsed) commands]
2022-08-23 18:59:52 +03:00
==
?: ?=([@ @ [@ @]] [parsed]) ::"revoke adminread from parent on database db"
2022-12-01 00:51:43 +03:00
%= $
2022-08-23 18:59:52 +03:00
script q.q.u.+3.q:revoke-nail
script-position next-cursor
2022-12-01 00:51:43 +03:00
commands
2022-08-23 18:59:52 +03:00
[`command-ast`(revoke:ast %revoke -.parsed +<.parsed +>.parsed) commands]
==
2022-08-24 02:30:27 +03:00
?: ?=([@ [@ [@ *]] [@ *]] [parsed]) ::"revoke Readwrite from ~zod,~bus,~nec,~sampel-palnet on namespace db.ns"
2022-12-01 00:51:43 +03:00
%= $ ::"revoke adminread from ~zod,~bus,~nec,~sampel-palnet on namespace ns" (ns previously cooked)
2022-08-24 02:30:27 +03:00
script q.q.u.+3.q:revoke-nail ::"revoke Readwrite from ~zod,~bus,~nec,~sampel-palnet on db.ns.table"
2022-08-23 18:59:52 +03:00
script-position next-cursor
2022-12-01 00:51:43 +03:00
commands
2022-08-24 02:30:27 +03:00
[`command-ast`(revoke:ast %revoke -.parsed +<+.parsed +>.parsed) commands]
2022-08-23 18:59:52 +03:00
==
?: ?=([@ @ [@ [@ *]]] [parsed]) ::"revoke readonly from siblings on namespace db.ns"
2022-12-01 00:51:43 +03:00
%= $ ::"revoke readwrite from moons on namespace ns" (ns previously cooked)
2022-08-23 18:59:52 +03:00
script q.q.u.+3.q:revoke-nail
script-position next-cursor
2022-12-01 00:51:43 +03:00
commands
2022-08-23 18:59:52 +03:00
[`command-ast`(revoke:ast %revoke -.parsed +<.parsed +>.parsed) commands]
==
2022-12-01 02:06:42 +03:00
~|("Cannot parse revoke {<parsed>}" !!)
2022-08-17 20:10:50 +03:00
%truncate-table
=/ truncate-table-nail (parse-truncate-table [[1 1] q.q.command-nail])
2022-12-01 00:51:43 +03:00
=/ next-cursor
2022-08-22 00:09:24 +03:00
(get-next-cursor [script-position +<.command-nail p.q.u.+3:q.+3:truncate-table-nail])
2022-08-21 03:29:26 +03:00
%= $
script q.q.u.+3.q:truncate-table-nail
script-position next-cursor
commands
2022-12-01 00:51:43 +03:00
[`command-ast`(truncate-table:ast %truncate-table (wonk truncate-table-nail)) commands]
2022-08-21 03:29:26 +03:00
==
2022-08-16 22:18:14 +03:00
==
2022-08-13 05:13:25 +03:00
--