Skip to main content

awSQL

The default exported module that holds and manages all database instances globally.

It does not provide any additional functionality beyond managing instances.


Methods


createInstance()

→ (hostname = String, username = String, password = String, options? = {charset?: String, defaultDatabase?: String, multipleStatements?: Boolean, insecureAuth?: Boolean, customIdentifier?: String, isDefault?: Boolean}) → Instance

Creates a new database connection instance.

Parameters

ParameterTypeDescription
hostnameStringThe database hostname.
usernameStringThe username for authentication.
passwordStringThe password for authentication.
options optionalObjectAdditional settings for the instance.
options.charset optionalStringThe character set to use.
options.defaultDatabase optionalStringDefault database for queries.
options.multipleStatements optionalBooleanAllow multiple SQL statements in a single query (default: false).
options.insecureAuth optionalBooleanEnables insecure authentication methods (default: false).
options.customIdentifier optionalStringCustom instance identifier. Defaults to username@hostname.
options.isDefault optionalBooleanMarks this instance as the default when no identifier is provided in getInstance().
Possible errors

This method may crash if:

  • password or username is empty.
  • An instance with the same identifier already exists.

Returns

Instance


getInstance()

→ (identifier? = String) → Instance / undefined

Retrieves an existing database instance by its identifier.

If no identifier is provided and a default instance exists, it returns the default instance.

Parameters

ParameterTypeDescription
identifier optionalStringThe name of the instance to retrieve. If no explicitly set with customIdentifier, instances are identified as username@hostname.

Returns

  • Instance - if found.
  • undefined - if no instance matches the identifier.

listInstances()

→ () → Array<String>

Returns a list of all defined instance identifiers.

Returns

Array<String> - A list of instance identifiers.


deleteInstance()

→ (identifier = String) → true

Deletes an existing instance and closes its database connection.

Parameters

ParameterTypeDescription
identifier optionalStringThe identifier of the instance to delete. If customIdentifier was not set, use username@hostname.
Possible Error

This method may crash if:

  • identifier is empty.
    • To delete the default instance, provide its identifier.
  • identifier is not a String.
  • No instance with the given identifier exists.

Returns

true - Awayls returns true. Errors will cause an exception instead.