The db module contains the Iguana Translator script functions that interact with databases. Functions exist to create local database tables, merge them with external databases, and perform queries on external databases.
All the database functions:
-
db conn: - new style: database methods using the database connection object.
-
db - old style database functions.
It is recommended best practice to use the new style database methods. They are easier to use and offer improved database transaction handling.
Advantages of the new style connection objects:
-
Connections are not pooled, resulting in safer transactions:
-
Create dedicated connections using
db.connect()
-
Legacy connections are pooled so it is possible (rarely) to receive a different connection and rollback a transaction
Note: If network connectivity to the database is lost, a rollback will occur with new and legacy connections
-
NEW! The ability to check a connection to confirm that the database is still available:
-
Use the
conn:check()
method to test a connection
Note: it is important to understand the behaviour of the live flag for db.connect and how it affects the execution the new style database methods in the Iguana editor:
-
By default the connection handle returned from db.connect is live (live = true).
-
If db.connect live = true (the default) connection methods will run in the editor (based on their default or live setting).
-
If db.connnect live = false it means that all database operations are always non-live.
-
For more information see the help for db.connect.
For more information on how Iguana Translator scripts work with databases, see Mapping To/From Databases.