Script directives
The first lines of a Script may declare what it is and what it takes, in -- comments. These lines are directives: BroadSQL reads them to check arguments, warn about the connection, and list or search Scripts. Each row links to the section that explains it in full.
-- @description: Largest countries of a continent
-- @instance: WORLD_APP
-- @environment: ALL
-- @tags: geo, reference
-- @status: stable
-- @access: read
-- @dialect: H2
-- @param continent TEXT "Continent, as in COUNTRY.CONTINENT"
-- @param min_population INTEGER = 50000000 "Smallest population listed"
SELECT CODE, NAME, POPULATION FROM COUNTRY
WHERE CONTINENT = ${continent} AND POPULATION >= ${min_population};
| Form | What it does | Example | Details |
|---|---|---|---|
-- @param <name> <type> [= <default>] ["<description>"] | Declares one typed parameter: TEXT, INTEGER, DECIMAL, BOOLEAN, DATE, TIMESTAMP or LIST OF <type>. With a default it is optional. | -- @param min_population INTEGER = 50000000 | Typed parameters |
-- @params: <name>, ... | Lists the arguments every call must pass, without types. Prefer -- @param for a new Script. | -- @params: country, min_id | Required arguments |
-- @description: <text> | A one-line description, shown by search and in the Editor. | -- @description: Monthly revenue by country | Metadata header |
-- @instance: <group>[, ...] | ALL | The Database Group(s) the Script is about. A mismatch with the current connection prints a warning; nothing is blocked. | -- @instance: WORLDAPP | What @instance and @environment do |
-- @environment: <environment>[, ...] | ALL | The Environment(s) the Script applies to. A mismatch prints a warning; nothing is blocked. | -- @environment: PROD | What @instance and @environment do |
-- @tags: <tag>, ... | Free text tags, matched by LIB FIND and grouped by LIB LIST ... BY TAG. | -- @tags: finance, monthly | Metadata header |
-- @status: draft | stable | deprecated | Information only, shown in listings. | -- @status: stable | Metadata header |
-- @access: read | write | Declares whether the Script changes data. Never enforced; LIB LINT reports a read Script that may write. | -- @access: read | What @access and @dialect do |
-- @dialect: <type>[, ...] | ANY | The connection types the Script is written for. On another type, BroadSQL warns and runs it anyway. | -- @dialect: PostgreSQL, H2 | What @access and @dialect do |
Rules for every directive
- Both
-- @key valueand-- @key: valuework, in--line comments or/* ... */block comments. @instance,@environment,@tags,@dialectand@paramsmay be repeated to add values;@paramis written once per parameter. For another key written twice, the first one wins.- Only
@paramand@paramscan refuse a call.@instanceand@environmentprint a warning on a mismatch and scope whatLIB LISTshows;@dialectprints a warning;@accessis checked byLIB LINTonly. @instancenames a Database Group: the name predates the Database Group rename and is kept in the file format.
Check a header
LIB SHOW <script>; prints the declared parameters, access and dialects; LIB LINT; reports unknown Database Groups, Environments and dialects, unreadable @param lines, and read Scripts that may write.
Related
- Scripts Library: metadata header
- Arguments and parameters
- Syntax and shortcuts
- Scripts Gallery: examples of complete headers.
Found something wrong or unclear on this page? Tell us, with the page address.