HyperScript
Docs

← All of the Docs Data and the outside

The database

effectrun sql <statement>since 1.7.23

Run a statement that changes something: INSERT, UPDATE, DELETE, CREATE TABLE

on load:
    run sql "CREATE TABLE IF NOT EXISTS visits (player VARCHAR(16), day VARCHAR(10))"
Try it
expressionsql rows of <query>since 1.7.23

Run a SELECT. The result is a list with a table for each row, its columns by their names in lower case. Up to 10,000 rows

command /visits:
    trigger:
        async:
            set {_rows} to sql rows of "SELECT day FROM visits WHERE player = ?" with player.name
            send "&7You have visited on %size of {_rows}% day(s)."
Try it
effectwith <value>, <value>since 1.7.23

After either: the values for the question marks in the statement, in order

on player join:
    run sql "INSERT INTO visits (player, day) VALUES (?, ?)" with player.name, server.date
Try it
Guide and examples

When HyperScript keeps its variables in a database (storage.type is sqlite, h2 or mysql), scripts can ask that database questions of their own: read what a website or another plugin wrote, or keep a table that is theirs.

on load:
    run sql "CREATE TABLE IF NOT EXISTS purchases (player VARCHAR(16), item VARCHAR(40), day VARCHAR(10))"

command /bought:
    players only: true
    trigger:
        async:
            set {_rows} to sql rows of "SELECT item, day FROM purchases WHERE player = ?" with player.name
            send "&7You have bought %size of {_rows}% thing(s)."
SyntaxMeaning
run sql <statement>Run a statement that changes something: INSERT, UPDATE, DELETE, CREATE TABLE
sql rows of <query>Run a SELECT. The result is a list with a table for each row, its columns by their names in lower case. Up to 10,000 rows
with <value>, <value>After either: the values for the question marks in the statement, in order
  • Put what players type after with, never into the statement itself. ... WHERE name = ? with arg.1 is safe whatever arg.1 is; gluing arg.1 into the text lets a player rewrite your question.
  • The database answers while the server waits. A question that may take a moment belongs in an async: block, as above.
  • This is the database HyperScript's own variables are in, in the tables hyperscript_variables and hyperscript_shared. Leave those two to HyperScript.
  • With storage.type: json or csv there is no database, and these two say so when they run.

Variables several servers have in common. With storage.shared-variables: true and every server using the same database, a variable whose name starts with shared. is the same on all of them: set {shared.event} to "double coins" on one server is what {shared.event} gives on the others a couple of seconds later (storage.shared-refresh). Every other variable stays each server's own. A shared variable is written the moment it changes; two servers changing the same one at the same moment do not add up, the later one wins, so add 1 to {shared.votes} from several servers at once can lose a count. A player's shared value is written with their name or id in it: {shared.coins.%player.uuid%}.