Querier

Abstract for Querier-services, cannot be used directly but rather as implemented by database-specific queriers.

What it does

When an implementation of this Service is hit, a query will be run, typically on a database.

It will branch depending on the size and influence of the executed query.

It is recommended to use the more generic SQL-service, so the database-connection may be elected based on the credentials.

Implementations

MySqlQuerier Connects to MySQL-compatible database and allows querying in accordance to Querier-abstract
SQLiteQuerier Opens SQLite-database and allows querying in accordance to Querier-abstract

How it works

// This example uses the MySqlQuerier implementation

{
    plugins = [
        f"Data.dll",
        f"InputProcessing.dll",
        f"BasicHttpServer.dll",
        f"OutputComposing.dll"];

    instances = {
        credentials = CredentialsStore(
            credset = "example",
            host = "localhost", db = "example",
            user = "example", pass = "example",
            pool = true);
    
        // Select Query producing text column
        list = MySqlQuerier(
            f"queries/Pies.sql"
            credset = "example"
        ) {
            // NoPies.html says there's no pies
            none->Template(f"templates/NoPies.html");
            // {% text %} tag in OnePie.html
            single->Template(f"templates/OnePie.html");
            // {% text %} tag in NPies.html
            iterator->Template(f"templates/NPies.html");
        };

        // Insert Query using @text-parameter
        save = MySqlQuerier(f"queries/SetPie.sql",
            credset = "example",
            params = ["text"]
        ) {
            oneaffected->Template(f"templates/Success.html");
        };

        form = PostFieldReader(
            showformafter = true,
            field_text = "^.{1,250}$"
        ) {
            // Form with textarea named 'text'
            form->Template(f"templates/Form.html");
            successful->instances.save;
        }

        server = HttpService(
            prefixes = ["http://localhost:8080/"]
        ) {
            http->Template(
                f"templates/List.html"
            ) {
                // {% list %} tag in List.html
                list->instances.list;
                // {% form %} tag in List.html
                form->instances.form;
            };
        };
    };
}

Settings

[default] or query a filesystem path to the query file that this service needs to execute
resultcap a numeric value indicating the maximal amount of result rows that should be accepted
params an array containing all string names of parameters used in this query. may be left empty if the query doesn't have parameters.
defaults default values for query parameters; these will be used if parameter names are not available in context

Branches

branch-name trigger interaction
none when no results have been produced from the query -
single when a single result has been produced ResultInteraction
first for the first result that has been produced ResultInteraction
iterator once for every result that has been produced ResultInteraction
successful after the query and subsequent branching was successful -
capreached after the resultcap has been reached -
noneAffected when the query has not changed the database -
oneAffected when the query has affected a single record -
someAffected when the query has affected some records -