github.com/voedger/voedger@v0.0.0-20240520144910-273e84102129/design/extensions/obsoleted/extensions.md (about) 1 # Declaration of extensions in vSQL. 2 This is a draft of vSQL syntax. Current version of the syntax can be found [here](../../pkg/parser/sql_example_app/pmain/package.vsql) 3 4 ## Declaration in PackageSchema 5 ### Projector 6 ```sql 7 package wasmprojectors 8 9 PROJECTOR myprojector ON ARG untill.PBill, ARG untill.Order ENGINE wasm 10 ``` 11 > Note: LANGUAGE is actually an Extension Kind. We use LANGUAGE because it's the part of SQL syntax (Cassandra, PostgreSQL, etc) 12 13 Syntax: 14 15 `PROJECTOR projector_name ON ARG qname | EVENT qname | ERRORS (',' ARG qname | EVENT qname | ERRORS)* ENGINE language` 16 17 Notes: 18 - `ON` is a conjunction of: 19 - `ARG <QName>` - handle events with specified arguments 20 - `EVENT <QName>` - handle specified events 21 - `ERRORS` - handle errors 22 23 ### Command 24 ```sql 25 package wasmcommands 26 27 COMMAND mycommand(untill.pbill) RETURNS sys.Json ENGINE wasm 28 ``` 29 Syntax: 30 31 `COMMAND command_name '(' params_schema [',' unlogged_params_schema] ')' [ RETURNS return_schema ] ENGINE language` 32 33 ### Query Function 34 ```sql 35 package wasmqueryfuncs 36 37 QUERYFUNC myqueryfunc(sys.Json) RETURNS sys.Json ENGINE wasm 38 ``` 39 Syntax: 40 41 `QUERYFUNC function_name '(' params_schema ')' [ RETURNS return_schema ] ENGINE language` 42 43 ## Use in the App Schema 44 ```sql 45 import "github.com/mycompany/mymodule/wasmprojectors" 46 import "github.com/mycompany/mymodule/wasmcommands" 47 import "github.com/mycompany/mymodule/wasmqueryfuncs" 48 49 ``` 50 51 ## Create Extension 52 ```bash 53 heeus ext init assemblyscript|tinygo|lua 54 ``` 55 Creates in the current package: 56 | File | Description | AssempblyScript | TinyGo | LUA 57 | ---------------------- | ---------------------- | --------------- | ------ | ---- 58 | extension.go\|ts\|lua | extension source code | + | + | + 59 | package.heeus | extension declaraion | + | + | + 60 | test.sh | run extension tests | + | + | + 61 | build.sh | build WASM file | + | + | - 62 63 ## Constraints 64 - Not possible to use both assemblyscript and tinygo langs within the same package. But it is possible to combine WASM and LUA extension kinds within the same package. 65 66 67 # Literature 68 - https://cassandra.apache.org/doc/latest/cassandra/cql/functions.html 69 - https://www.ibm.com/docs/en/db2/11.1?topic=statements-create-procedure-sql 70 - https://www.postgresql.org/docs/current/sql-createprocedure.html 71 72 # See Also 73 - [Heeus: Repository & Application Schema](https://github.com/heeus/heeus-design#repository--application-schema) 74 - https://github.com/heeus/heeus 75 - https://github.com/heeus/inv-go/blob/master/20220221-parsing/participle/schema.vsql