mirror of
https://github.com/jackfoxy/urQL.git
synced 2024-09-11 11:55:33 +03:00
truncate table
This commit is contained in:
parent
f5e90622ff
commit
7ce74851c7
@ -1,5 +1,5 @@
|
||||
/- ast
|
||||
|%
|
||||
|_ current-database=@t :: (parse:parse(current-database '<db>') "<script>")
|
||||
+$ command-ast
|
||||
$%
|
||||
create-database:ast
|
||||
@ -47,31 +47,26 @@
|
||||
==
|
||||
(fail tub)
|
||||
$(p.tub (lust i.q.tub p.tub), q.tub t.q.tub, daf (rsh 3 daf))
|
||||
::++ cook-qualified-object
|
||||
:: |= a=*
|
||||
:: [43.332 [i=25.188 t=~] [i=29.550 t=~] [i=1.701.667.182 t=~]] ~firsub.db.ns.name
|
||||
:: [43.332 [i=25.188 t=~] '' 'name' ~] ~firsub..ns.name
|
||||
:: [[i=25.188 t=~] [i=29.550 t=~] [i=1.701.667.182 t=~]] db.ns.name
|
||||
:: [[i=25.188 t=~] '' 'name' ~] db..name
|
||||
:: [[i=29.550 t=~] [i=1.701.667.182 t=~]] ns.name
|
||||
++ cook-qualified-object
|
||||
|= a=*
|
||||
?: ?=([@ [@ %~] [@ %~] [@ %~]] a) :: ~firsub.db.ns.name
|
||||
(qualified-object:ast %qualified-object ``@p`-.a `@t`+<-.a `@t`+>-<.a `@t`+>+<.a)
|
||||
?: ?=([@ [@ %~] * [@ %~]] a) ::~firsub..ns.name
|
||||
(qualified-object:ast %qualified-object ``@p`-.a `@t`+<-.a 'dbo' `@t`+>+<.a)
|
||||
?: ?=([[@ %~] [@ %~] [@ %~]] a) :: db.ns.name
|
||||
(qualified-object:ast %qualified-object ~ `@t`-<.a `@t`+<-.a `@t`+>-.a)
|
||||
?: ?=([[@ %~] * [@ %~]] a) :: db..name
|
||||
(qualified-object:ast %qualified-object ~ `@t`-<.a 'dbo' `@t`+>-.a)
|
||||
?: ?=([[@ %~] [@ %~]] a) :: ns.name
|
||||
(qualified-object:ast %qualified-object ~ current-database `@t`-<.a `@t`+<.a)
|
||||
?: ?=([@ %~] a) :: name
|
||||
(qualified-object:ast %qualified-object ~ current-database 'dbo' `@t`-.a)
|
||||
!!
|
||||
::
|
||||
:: parse urQL script
|
||||
::
|
||||
::++ cook-four-pat-ps
|
||||
:: |= a=[[@ @] * [@ @] * [@ @] * [@ @]]
|
||||
:: ;:(weld (trip `@t`-<.a) (trip `@t`->.a) "-" (trip `@t`+>-<.a) (trip `@t`+>->.a) "-" (trip `@t`+>+>-<.a) (trip `@t`+>+>->.a) "-" (trip `@t`+>+>+>-.a) (trip `@t`+>+>+>+.a))
|
||||
::++ cook-galaxy
|
||||
:: |= a=[@ @]
|
||||
:: ['~' (trip +.a)]
|
||||
::++ cook-star
|
||||
:: |= a=[* [@ @]]
|
||||
:: ;:(weld "~" (trip `@t`+<.a) (trip `@t`+>.a))
|
||||
::++ cook-planet
|
||||
:: |= a=[* [@ @] * [@ @]]
|
||||
:: ;:(weld "~" (trip `@t`+<-.a) (trip `@t`+<+.a) "-" (trip `@t`+>+<.a) (trip `@t`+>+>.a))
|
||||
::++ cook-moon
|
||||
:: |= a=[@ tape]
|
||||
:: ['~' +.a]
|
||||
++ parse
|
||||
|= [current-database=@t script=tape]
|
||||
|= script=tape
|
||||
~| 'Input script is empty.'
|
||||
?> !=((lent script) 0)
|
||||
^- (list command-ast)
|
||||
@ -93,11 +88,7 @@
|
||||
=/ parse-qualified-3-name ;~(pfix whitespace parse-qualified-3)
|
||||
=/ parse-force-or-3-name ;~(pose ;~(pfix whitespace (jester 'force')) parse-qualified-3-name)
|
||||
=/ parse-ship ;~(pfix sig fed:ag)
|
||||
=/ parse-qualified-object ;~ pose
|
||||
;~((glue dot) parse-ship (star sym) (star sym) (star sym))
|
||||
;~((glue dot) parse-ship (star sym) dot dot (star sym))
|
||||
parse-qualified-3
|
||||
==
|
||||
=/ parse-qualified-object (cook cook-qualified-object ;~(pose ;~((glue dot) parse-ship (star sym) (star sym) (star sym)) ;~((glue dot) parse-ship (star sym) dot dot (star sym)) parse-qualified-3))
|
||||
=/ parse-force-qualified-name ;~ sfix
|
||||
;~(pose ;~(plug parse-force-or-3-name parse-qualified-3-name) parse-qualified-3-name)
|
||||
end-or-next-command
|
||||
@ -306,27 +297,15 @@
|
||||
==
|
||||
~| "Cannot parse truncate-table {<p.q.command-nail>}"
|
||||
=/ truncate-table-nail (parse-truncate-table [[1 1] q.q.command-nail])
|
||||
=/ parsed (wonk truncate-table-nail)
|
||||
=/ cursor p.-.truncate-table-nail
|
||||
=/ next-cursor ?: (gth -.cursor -.script-position) :: if we advanced to next input line
|
||||
[(add -.cursor -.script-position) +.cursor] :: add lines and use nail cursor column
|
||||
[-.cursor (add +.cursor +.script-position)] :: else add column positions
|
||||
|
||||
~| "parsed: {<parsed>}"
|
||||
:: ~| "next-cursor: {<next-cursor>}"
|
||||
|
||||
=/ yikes 0
|
||||
!!
|
||||
|
||||
::[['~' 'z' 'o' 'd'] [i=25.188 t=~] [i=29.550 t=~] [i=1.701.667.182 t=~]]
|
||||
:: ?: ?=([[@ [@ %~] [@ %~] [@ %~]]] parsed) :: "truncate table ~zod.db.ns.name"
|
||||
:: %= $
|
||||
:: script q.q.u.+3.q:truncate-table-nail
|
||||
:: script-position next-cursor
|
||||
:: commands
|
||||
:: [`command-ast`(truncate-table:ast %truncate-table (unit 'zod') 'db' 'ns' 'name') commands]
|
||||
:: [`command-ast`(truncate-table:ast %truncate-table (unit -.parsed) i.+<.parsed i.+>.parsed i.+>+.parsed) commands]
|
||||
:: ==
|
||||
:: !!
|
||||
%= $
|
||||
script q.q.u.+3.q:truncate-table-nail
|
||||
script-position next-cursor
|
||||
commands
|
||||
[`command-ast`(truncate-table:ast %truncate-table (wonk truncate-table-nail)) commands]
|
||||
==
|
||||
==
|
||||
--
|
||||
|
@ -213,10 +213,7 @@
|
||||
+$ truncate-table
|
||||
$:
|
||||
%truncate-table
|
||||
ship=(unit @p)
|
||||
database-name=@t
|
||||
namespace=@t
|
||||
table-name=@t
|
||||
table=qualified-object
|
||||
==
|
||||
::
|
||||
:: create ASTs
|
||||
|
@ -18,29 +18,33 @@
|
||||
:: current database must be proper face
|
||||
++ test-current-database
|
||||
%- expect-fail
|
||||
|. (parse:parse ['Other-db' "cReate\0d\09 namespace my-namespace"])
|
||||
|. (parse:parse(current-database 'oTher-db') "cReate\0d\09 namespace my-namespace")
|
||||
::
|
||||
:: create database
|
||||
::
|
||||
:: tests 1, 3, and extra whitespace characters
|
||||
++ test-create-database-1
|
||||
%+ expect-eq
|
||||
!> ~[[%create-database name='my-database']]
|
||||
!> (parse:parse ['dummy' "cReate datAbase \0a my-database "])
|
||||
!> (parse:parse(current-database 'dummy') "cReate datAbase \0a my-database ")
|
||||
::
|
||||
:: subsequent commands ignored
|
||||
++ test-create-database-2
|
||||
%+ expect-eq
|
||||
!> ~[[%create-database name='my-database']]
|
||||
!> (parse:parse ['dummy' "cReate datAbase \0a my-database; cReate namesPace my-db.another-namespace"])
|
||||
!> (parse:parse(current-database 'dummy') "cReate datAbase \0a my-database; cReate namesPace my-db.another-namespace")
|
||||
::
|
||||
:: fail when database name is not a face
|
||||
:: fail when database name is not a term
|
||||
++ test-create-database-3
|
||||
%- expect-fail
|
||||
|. (parse:parse ['dummy' "cReate datAbase My-database"])
|
||||
|. (parse:parse(current-database 'dummy') "cReate datAbase My-database")
|
||||
::
|
||||
:: fail when commands are prior to create database
|
||||
++ test-create-database-4
|
||||
%- expect-fail
|
||||
|. (parse:parse ['dummy' "create namespace my-namespace ; cReate datAbase my-database"])
|
||||
|. (parse:parse(current-database 'dummy') "create namespace my-namespace ; cReate datAbase my-database")
|
||||
::
|
||||
:: create namespace
|
||||
::
|
||||
:: tests 1, 2, 3, 5, and extra whitespace characters
|
||||
++ test-create-namespace-1
|
||||
@ -48,24 +52,25 @@
|
||||
=/ expected2 [%create-namespace database-name='my-db' name='another-namespace']
|
||||
%+ expect-eq
|
||||
!> ~[expected1 expected2]
|
||||
!> %- parse:parse
|
||||
['other-db' "cReate\0d\09 namespace my-namespace ; cReate namesPace my-db.another-namespace"]
|
||||
!> (parse:parse(current-database 'other-db') "cReate\0d\09 namespace my-namespace ; cReate namesPace my-db.another-namespace")
|
||||
::
|
||||
:: leading and trailing whitespace characters, end delimiter not required on single
|
||||
++ test-create-namespace-2
|
||||
%+ expect-eq
|
||||
!> ~[[%create-namespace database-name='other-db' name='my-namespace']]
|
||||
!> (parse:parse ['other-db' " \09cReate\0d\09 namespace my-namespace "])
|
||||
!> (parse:parse(current-database 'other-db') " \09cReate\0d\09 namespace my-namespace ")
|
||||
::
|
||||
:: fail when database qualifier is not a face
|
||||
:: fail when database qualifier is not a term
|
||||
++ test-create-namespace-3
|
||||
%- expect-fail
|
||||
|. (parse:parse ['other-db' "cReate namesPace Bad-face.another-namespace"])
|
||||
|. (parse:parse(current-database 'other-db') "cReate namesPace Bad-face.another-namespace")
|
||||
::
|
||||
:: fail when namespace is not a face
|
||||
:: fail when namespace is not a term
|
||||
++ test-create-namespace-4
|
||||
%- expect-fail
|
||||
|. (parse:parse ['other-db' "cReate namesPace my-db.Bad-face"])
|
||||
|. (parse:parse(current-database 'other-db') "cReate namesPace my-db.Bad-face")
|
||||
::
|
||||
:: drop table
|
||||
::
|
||||
:: tests 1, 2, 3, 5, and extra whitespace characters
|
||||
++ test-drop-table-1
|
||||
@ -73,57 +78,59 @@
|
||||
=/ expected2 [%drop-table database-name='db' namespace='ns' name='name' force=%.n]
|
||||
%+ expect-eq
|
||||
!> ~[expected1 expected2]
|
||||
!> %- parse:parse
|
||||
['other-db' "droP table FORce db.ns.name;droP table \0a db.ns.name"]
|
||||
!> (parse:parse(current-database 'other-db') "droP table FORce db.ns.name;droP table \0a db.ns.name")
|
||||
::
|
||||
:: leading and trailing whitespace characters, end delimiter not required on single
|
||||
:: leading and trailing whitespace characters, end delimiter not required on single, force db..name
|
||||
++ test-drop-table-2
|
||||
%+ expect-eq
|
||||
!> ~[[%drop-table database-name='db' namespace='dbo' name='name' force=%.y]]
|
||||
!> (parse:parse ['other-db' " \09drop\0d\09 table\0aforce db..name "])
|
||||
!> (parse:parse(current-database 'other-db') " \09drop\0d\09 table\0aforce db..name ")
|
||||
::
|
||||
:: db..name
|
||||
++ test-drop-table-3
|
||||
%+ expect-eq
|
||||
!> ~[[%drop-table database-name='db' namespace='dbo' name='name' force=%.n]]
|
||||
!> (parse:parse ['other-db' "drop table db..name"])
|
||||
!> (parse:parse(current-database 'other-db') "drop table db..name")
|
||||
::
|
||||
:: force ns.name
|
||||
++ test-drop-table-4
|
||||
%+ expect-eq
|
||||
!> ~[[%drop-table database-name='other-db' namespace='ns' name='name' force=%.y]]
|
||||
!> (parse:parse ['other-db' "drop table force ns.name"])
|
||||
!> (parse:parse(current-database 'other-db') "drop table force ns.name")
|
||||
::
|
||||
:: ns.name
|
||||
++ test-drop-table-5
|
||||
%+ expect-eq
|
||||
!> ~[[%drop-table database-name='other-db' namespace='ns' name='name' force=%.n]]
|
||||
!> (parse:parse ['other-db' "drop table ns.name"])
|
||||
!> (parse:parse(current-database 'other-db') "drop table ns.name")
|
||||
::
|
||||
:: force name
|
||||
++ test-drop-table-6
|
||||
%+ expect-eq
|
||||
!> ~[[%drop-table database-name='other-db' namespace='ns' name='name' force=%.y]]
|
||||
!> (parse:parse ['other-db' "drop table force ns.name"])
|
||||
!> ~[[%drop-table database-name='other-db' namespace='dbo' name='name' force=%.y]]
|
||||
!> (parse:parse(current-database 'other-db') "DROP table FORCE name")
|
||||
:: name
|
||||
++ test-drop-table-7
|
||||
%+ expect-eq
|
||||
!> ~[[%drop-table database-name='other-db' namespace='ns' name='name' force=%.n]]
|
||||
!> (parse:parse ['other-db' "drop table ns.name"])
|
||||
++ test-drop-table-8
|
||||
%+ expect-eq
|
||||
!> ~[[%drop-table database-name='other-db' namespace='dbo' name='name' force=%.y]]
|
||||
!> (parse:parse ['other-db' "DROP table FORCE name"])
|
||||
++ test-drop-table-9
|
||||
%+ expect-eq
|
||||
!> ~[[%drop-table database-name='other-db' namespace='dbo' name='name' force=%.n]]
|
||||
!> (parse:parse ['other-db' "DROP table name"])
|
||||
!> (parse:parse(current-database 'other-db') "DROP table name")
|
||||
::
|
||||
:: fail when database qualifier is not a face
|
||||
:: fail when database qualifier is not a term
|
||||
++ test-drop-table-8
|
||||
%- expect-fail
|
||||
|. (parse:parse(current-database 'other-db') "DROP table Db.ns.name")
|
||||
|
||||
:: fail when namespace qualifier is not a term
|
||||
++ test-drop-table-9
|
||||
%- expect-fail
|
||||
|. (parse:parse(current-database 'other-db') "DROP table db.nS.name")
|
||||
::
|
||||
:: fail when table name is not a term
|
||||
++ test-drop-table-10
|
||||
%- expect-fail
|
||||
|. (parse:parse ['other-db' "DROP table Db.ns.name"])
|
||||
|
||||
:: fail when namespace qualifier is not a face
|
||||
++ test-drop-table-11
|
||||
%- expect-fail
|
||||
|. (parse:parse ['other-db' "DROP table db.nS.name"])
|
||||
|. (parse:parse(current-database 'other-db') "DROP table db.ns.nAme")
|
||||
::
|
||||
:: fail when table name is not a face
|
||||
++ test-drop-table-12
|
||||
%- expect-fail
|
||||
|. (parse:parse ['other-db' "DROP table db.ns.nAme"])
|
||||
:: drop view
|
||||
::
|
||||
:: tests 1, 2, 3, 5, and extra whitespace characters
|
||||
++ test-drop-view-1
|
||||
@ -131,55 +138,115 @@
|
||||
=/ expected2 [%drop-view database-name='db' namespace='ns' name='name' force=%.n]
|
||||
%+ expect-eq
|
||||
!> ~[expected1 expected2]
|
||||
!> %- parse:parse
|
||||
['other-db' "droP View FORce db.ns.name;droP View \0a db.ns.name"]
|
||||
!> (parse:parse(current-database 'other-db') "droP View FORce db.ns.name;droP View \0a db.ns.name")
|
||||
::
|
||||
:: leading and trailing whitespace characters, end delimiter not required on single
|
||||
:: leading and trailing whitespace characters, end delimiter not required on single, force db..name
|
||||
++ test-drop-view-2
|
||||
%+ expect-eq
|
||||
!> ~[[%drop-view database-name='db' namespace='dbo' name='name' force=%.y]]
|
||||
!> (parse:parse ['other-db' " \09drop\0d\09 vIew\0aforce db..name "])
|
||||
!> (parse:parse(current-database 'other-db') " \09drop\0d\09 vIew\0aforce db..name ")
|
||||
::
|
||||
:: db..name
|
||||
++ test-drop-view-3
|
||||
%+ expect-eq
|
||||
!> ~[[%drop-view database-name='db' namespace='dbo' name='name' force=%.n]]
|
||||
!> (parse:parse ['other-db' "drop view db..name"])
|
||||
!> (parse:parse(current-database 'other-db') "drop view db..name")
|
||||
::
|
||||
:: force ns.name
|
||||
++ test-drop-view-4
|
||||
%+ expect-eq
|
||||
!> ~[[%drop-view database-name='other-db' namespace='ns' name='name' force=%.y]]
|
||||
!> (parse:parse ['other-db' "drop view force ns.name"])
|
||||
!> (parse:parse(current-database 'other-db') "drop view force ns.name")
|
||||
::
|
||||
:: ns.name
|
||||
++ test-drop-view-5
|
||||
%+ expect-eq
|
||||
!> ~[[%drop-view database-name='other-db' namespace='ns' name='name' force=%.n]]
|
||||
!> (parse:parse ['other-db' "drop view ns.name"])
|
||||
!> (parse:parse(current-database 'other-db') "drop view ns.name")
|
||||
::
|
||||
:: force name
|
||||
++ test-drop-view-6
|
||||
%+ expect-eq
|
||||
!> ~[[%drop-view database-name='other-db' namespace='ns' name='name' force=%.y]]
|
||||
!> (parse:parse ['other-db' "drop view force ns.name"])
|
||||
!> ~[[%drop-view database-name='other-db' namespace='dbo' name='name' force=%.y]]
|
||||
!> (parse:parse(current-database 'other-db') "DROP VIEW FORCE name")
|
||||
::
|
||||
:: name
|
||||
++ test-drop-view-7
|
||||
%+ expect-eq
|
||||
!> ~[[%drop-view database-name='other-db' namespace='ns' name='name' force=%.n]]
|
||||
!> (parse:parse ['other-db' "drop view ns.name"])
|
||||
++ test-drop-view-8
|
||||
%+ expect-eq
|
||||
!> ~[[%drop-view database-name='other-db' namespace='dbo' name='name' force=%.y]]
|
||||
!> (parse:parse ['other-db' "DROP VIEW FORCE name"])
|
||||
++ test-drop-view-9
|
||||
%+ expect-eq
|
||||
!> ~[[%drop-view database-name='other-db' namespace='dbo' name='name' force=%.n]]
|
||||
!> (parse:parse ['other-db' "DROP VIEW name"])
|
||||
!> ~[[%drop-view database-name='other-db' namespace='dbo' name='name' force=%.n]]
|
||||
!> (parse:parse(current-database 'other-db') "DROP VIEW name")
|
||||
::
|
||||
:: fail when database qualifier is not a face
|
||||
:: fail when database qualifier is not a term
|
||||
++ test-drop-view-8
|
||||
%- expect-fail
|
||||
|. (parse:parse(current-database 'other-db') "DROP VIEW Db.ns.name")
|
||||
|
||||
:: fail when namespace qualifier is not a term
|
||||
++ test-drop-view-9
|
||||
%- expect-fail
|
||||
|. (parse:parse(current-database 'other-db') "DROP VIEW db.nS.name")
|
||||
::
|
||||
:: fail when view name is not a term
|
||||
++ test-drop-view-10
|
||||
%- expect-fail
|
||||
|. (parse:parse ['other-db' "DROP VIEW Db.ns.name"])
|
||||
|
||||
:: fail when namespace qualifier is not a face
|
||||
++ test-drop-view-11
|
||||
%- expect-fail
|
||||
|. (parse:parse ['other-db' "DROP VIEW db.nS.name"])
|
||||
|. (parse:parse(current-database 'other-db') "DROP VIEW db.ns.nAme")
|
||||
::
|
||||
:: fail when view name is not a face
|
||||
++ test-drop-view-12
|
||||
:: truncate table
|
||||
::
|
||||
:: tests 1, 2, 3, 5, and extra whitespace characters
|
||||
++ test-truncate-table-1
|
||||
=/ expected1 [%truncate-table table=[%qualified-object ship=[~ ~zod] database='db' namespace='ns' name='name']]
|
||||
=/ expected2 [%truncate-table table=[%qualified-object ship=[~ ~sampel-palnet] database='db' namespace='dbo' name='name']]
|
||||
%+ expect-eq
|
||||
!> ~[expected1 expected2]
|
||||
!> (parse:parse(current-database 'dummy') " \0atrUncate TAble\0d ~zod.db.ns.name\0a; truncate table ~sampel-palnet.db..name")
|
||||
::
|
||||
:: leading and trailing whitespace characters, end delimiter not required on single, db.ns.name
|
||||
++ test-truncate-table-2
|
||||
%+ expect-eq
|
||||
!> ~[[%truncate-table table=[%qualified-object ship=~ database='db' namespace='ns' name='name']]]
|
||||
!> (parse:parse(current-database 'dummy') " \09truncate\0d\09 TaBle\0a db.ns.name ")
|
||||
::
|
||||
:: db..name
|
||||
++ test-truncate-table-3
|
||||
%+ expect-eq
|
||||
!> ~[[%truncate-table table=[%qualified-object ship=~ database='db' namespace='dbo' name='name']]]
|
||||
!> (parse:parse(current-database 'dummy') "truncate table db..name")
|
||||
::
|
||||
:: ns.name
|
||||
++ test-truncate-table-4
|
||||
%+ expect-eq
|
||||
!> ~[[%truncate-table table=[%qualified-object ship=~ database='dummy' namespace='ns' name='name']]]
|
||||
!> (parse:parse(current-database 'dummy') "truncate table ns.name")
|
||||
::
|
||||
:: name
|
||||
++ test-truncate-table-5
|
||||
%+ expect-eq
|
||||
!> ~[[%truncate-table table=[%qualified-object ship=~ database='dummy' namespace='dbo' name='name']]]
|
||||
!> (parse:parse(current-database 'dummy') "truncate table name")
|
||||
::
|
||||
:: fail when database qualifier is not a term
|
||||
++ test-truncate-table-6
|
||||
%- expect-fail
|
||||
|. (parse:parse ['other-db' "DROP VIEW db.ns.nAme"])
|
||||
|. (parse:parse(current-database 'dummy') "truncate table Db.ns.name")
|
||||
|
||||
:: fail when namespace qualifier is not a term
|
||||
++ test-truncate-table-7
|
||||
%- expect-fail
|
||||
|. (parse:parse(current-database 'dummy') "truncate table db.nS.name")
|
||||
::
|
||||
:: fail when view name is not a term
|
||||
++ test-truncate-table-8
|
||||
%- expect-fail
|
||||
|. (parse:parse(current-database 'dummy') "truncate table db.ns.nAme")
|
||||
::
|
||||
:: fail when view name is not a term
|
||||
++ test-truncate-table-9
|
||||
%- expect-fail
|
||||
|. (parse:parse(current-database 'dummy') "truncate table db.ns.nAme")
|
||||
::
|
||||
:: fail when ship is invalid
|
||||
++ test-truncate-table-10
|
||||
%- expect-fail
|
||||
|. (parse:parse(current-database 'dummy') "truncate table ~shitty-shippp db.ns.nAme")
|
||||
--
|
||||
|
Loading…
Reference in New Issue
Block a user