Skip to content
Brian edited this page May 15, 2016 · 2 revisions

JSQL has a cascading options system. Each section below specified an place where options can be set; each subsequent option setting will overwrite the options above it (with some exceptions, which will be noted).

Table of Contents

cls.DefaultOptions

This is the first place options are set, and has default values which have some sanity to them. Most consumer code will be happy with these values, and will not need to do anything with options at all. If you want to write a piece of code to modify JSQL options across your whole campaign, modifying the values of cls.DefaultOptions is the way to do it.

Option Type Used by Description
typeHandlers Array of Strings or Functions createTable, alterTable Additional handlers for custom column types. Calling cls.registerTypeHandler is preferred, but this option (ha!) is available.
autoIncrementStartValue Number createTable, alterTable The starting value for an autoincrement field
createTableIfNotExists Boolean createTable Suppresses the error that would be generated when attempting to create a table that already exists
dropTableIfExists Boolean dropTable Suppress the error that would be generated when attempting to drop a table that doesn't exist
createTriggerIfNotExists Boolean createTrigger Suppress the error that would be generated when attempting to create a trigger that already exists
dropTriggerIfExists Boolean dropTrigger Suppress the error that would be generated when attempting to drop a trigger that doesn't exist
useTransaction cls.Transaction createTable, alterTable, dropTable, delete, insert, update, createTrigger, dropTrigger Adds a query to the given Transaction instead of executing it immediately
selectAsObjects Boolean select The return value from a select query will be an array of objects, instead of an array of arrays. Each key in the objects will be the name of the column.
triggerParamsAsObjects Boolean delete, insert, update The parameters passed to trigger callback functions will be arrays of objects, instead of arrays of arrays. Each key in the objects will be the name of the column.

User Options

Using One-Click Install features, you can set the value of most options without touching code. This category does not quite overwrite the cls.DefaultOptions, it is merely a different means of setting their values. If you set the values of cls.DefaultOptions in code later, that value will beat the User Options value until you change the User Options again.

All options in cls.DefaultOptions can be set from User Options except typeHandlers and useTransaction.

cls.QueryBuilder Constructors

Each of the cls.QueryBuilder subclasses (CreateTable, AlterTable, DropTable, Delete, Insert, Update, Select, CreateTrigger, and DropTrigger) can have an options object passed to their constructor. Any values in this object will overwrite equivalent values from cls.DefaultOptions for that query only.

CreateTable and CreateTrigger

In addition to the values from cls.DefaultOptions, you can use ifNotExists as an alias for createTableIfNotExists and createTriggerIfNotExists.

DropTable and DropTrigger

In addition to the values from cls.DefaultOptions, you can use ifExists as an alias for dropTableIfExists and dropTriggerIfExists.

cls.Block Functions

Certain cls.Block functions can accept can have an options object passed to them. Options passed to these functions cannot be overwritten, because the values are used immediately.

Option Function
typeHandlers createTable#field, createTable#fields, alterTable#field, alterTable#fields, alterTable#changeFieldType
autoincrementStartValue alterTable#resetFieldIndex

execute() and commit()

Any options relevant to the query (other than ones passed to cls.Block functions, mentioned in the section above) can be overridden in the execute function.

Because of the way transactions function, any options you would otherwise to pass to execute in a transaction-based query must be options on the Transaction object. That means either passing them to the Transaction constructor (jsql.transaction(...)) or to the transaction's commit.

Clone this wiki locally