The DB2 iSeries connector enables LoopBack applications to connect to DB2 iSeries data sources.Note: This page was generated from the loopback-connector-db2iseries/README.md.

loopback-connector-db2iseries

IBM® DB2® for iSeries is the database of choice for robust, enterprise-wide solutions handling high-volume workloads.It is optimized to deliver industry-leading performance while lowering costs. The loopback-connector-db2iseriesmodule is the LoopBack connector for DB2 for iSeries.

The LoopBack DB2 for iSeries connector supports:

Installation

Enter the following in the top-level directory of your LoopBack application:

  1. $ npm install loopback-connector-db2iseries --save

The —save option adds the dependency to the application’s package.json file.

Configuration

Use the data source generator to add the DB2 for iSeries data source to your application.The entry in the application’s server/datasources.json will look something like this:

  1. "mydb": {
  2. "name": "mydb",
  3. "connector": "db2iseries"
  4. }

Edit server/datasources.json to add other supported properties as required:

  1. "mydb": {
  2. "name": "mydb",
  3. "connector": "db2iseries",
  4. "username": <username>,
  5. "password": <password>,
  6. "database": <database name>,
  7. "hostname": <db2 server hostname>,
  8. "port": <port number>
  9. }

The following table describes the connector properties.

Property Type Description
databaseStringDatabase name
schemaStringSpecifies the default schema name that is used to qualify unqualified database objects in dynamically prepared SQL statements. The value of this property sets the value in the CURRENT SCHEMA special register on the database server. The schema name is case-sensitive, and must be specified in uppercase characters
usernameStringDB2 Username
passwordStringDB2 password associated with the username above
hostnameStringDB2 server hostname or IP address
portStringDB2 server TCP port number
useLimitOffsetBooleanLIMIT and OFFSET must be configured on the DB2 server before use (compatibility mode)
supportDashDBBooleanCreate ROW ORGANIZED tables to support dashDB.

Alternatively, you can create and configure the data source in JavaScript code.For example:

  1. var DataSource = require('loopback-datasource-juggler').DataSource;
  2. var DB2 = require('loopback-connector-db2iseries');
  3. var config = {
  4. username: process.env.DB2_USERNAME,
  5. password: process.env.DB2_PASSWORD,
  6. hostname: process.env.DB2_HOSTNAME,
  7. port: 50000,
  8. database: 'SQLDB',
  9. };
  10. var db = new DataSource(DB2, config);
  11. var User = db.define('User', {
  12. name: { type: String },
  13. email: { type: String },
  14. });
  15. db.autoupdate('User', function(err) {
  16. if (err) {
  17. console.log(err);
  18. return;
  19. }
  20. User.create({
  21. name: 'Tony',
  22. email: 'tony@t.com',
  23. }, function(err, user) {
  24. console.log(err, user);
  25. });
  26. User.find({ where: { name: 'Tony' }}, function(err, users) {
  27. console.log(err, users);
  28. });
  29. User.destroyAll(function() {
  30. console.log('example complete');
  31. });
  32. });

Tags: connectorsreadme