以下适用于luban-h5的v1.8.1
    1.8.1 (2020-01-12)

    1. 安装 oracledb
    1. npm install oracledb
    1. back-end\h5-api\config\environments\development\database.json

    注:username就是数据库的用户名,由于框架原因,创建数据库用户时要注意,用户名前后必须带半角双引号。

    1. {
    2. "defaultConnection": "default",
    3. "enabled": true,
    4. "connections": {
    5. "default": {
    6. "connector": "bookshelf",
    7. "settings": {
    8. "client": "oracledb",
    9. "connectString": "ip:port/orcl",
    10. "username": "\"luban\"",
    11. "password": "your password",
    12. "charset": "utf8"
    13. },
    14. "options": {
    15. "debug": true,
    16. "pool": {
    17. "acquireTimeoutMillis": 60000,
    18. "min": 0,
    19. "max": 7
    20. },
    21. "acquireConnectionTimeout": 600000,
    22. "useNullAsDefault": true,
    23. "fetchAsString": ["clob"]
    24. }
    25. }
    26. }
    27. }
    1. back-end\h5-api\node_modules\bookshelf\lib\sync.js
    1. // Sync
    2. // ---------------
    3. 'use strict';
    4. const _ = require('lodash');
    5. const Promise = require('bluebird');
    6. const validLocks = ['forShare', 'forUpdate'];
    7. function supportsReturning(client = {}) {
    8. if (!client.config || !client.config.client) return false;
    9. return ['postgresql', 'postgres', 'pg', 'oracle', 'mssql', 'oracledb'].includes(client.config.client);
    10. }

    4.back-end\h5-api\node_modules\strapi-connector-bookshelf\lib\knex.js

    1. /* eslint-disable prefer-template */
    2. // Array of supported clients.
    3. const CLIENTS = [
    4. 'pg',
    5. 'mysql',
    6. 'mysql2',
    7. 'sqlite3',
    8. 'mariasql',
    9. 'oracle',
    10. 'oracledb',
    11. 'strong-oracle',
    12. 'mssql',
    13. ];
    1. ssl: _.get(connection.settings, 'ssl', false),
    2. timezone: _.get(connection.settings, 'timezone', 'utc'),
    3. filename: _.get(connection.settings, 'filename', '.tmp/data.db'),
    4. connectString: _.get(connection.settings, 'connectString'),
    5. 增加oracledbfetchAsString属性的支持,处理blob字段
    6. // Resolve path to the directory containing the database file.
    7. const fileDirectory = options.connection.filename
    8. ? path.dirname(path.resolve(strapi.config.appPath, options.connection.filename))
    9. : '';
    10. switch(options.client) {
    11. case 'oracledb':
    12. options.fetchAsString = _.get(connection.options, 'fetchAsString', []);
    13. break;
    1. back-end\h5-api\node_modules\knex\lib\query\builder.js
    1. 增加空字符串判断逻辑
    2. if (arguments.length === 2) {
    3. value = operator;
    4. operator = '='; // If the value is null, and it's a two argument query,
    5. // we assume we're going for a `whereNull`.
    6. if ((this.client.config.client === 'oracledb' && (typeof value === "undefined" || value === '')) || value === null) {
    7. return this.whereNull(column);
    8. }
    9. } // lower case the operator for comparison purposes
    10. 增加空字符串判断逻辑
    11. // If the value is still null, check whether they're meaning
    12. // where value is null
    13. if ((this.client.config.client === 'oracledb' && (typeof value === "undefined" || value === '')) || value === null) {
    14. // Check for .where(key, 'is', null) or .where(key, 'is not', 'null');
    15. if (checkOperator === 'is' || checkOperator === 'is not') {
    16. return this._not(checkOperator === 'is not').whereNull(column);
    17. }
    18. } // Push onto the where statement stack.
    19. 6. back-end\h5-api\node_modules\strapi-connector-bookshelf\lib\mount-models.js
    20. ```js
    21. const getDatabaseName = connection => {
    22. const dbName = _.get(connection.settings, 'database');
    23. const dbSchema = _.get(connection.settings, 'schema', 'public');
    24. switch (_.get(connection.settings, 'client')) {
    25. case 'sqlite3':
    26. return 'main';
    27. case 'pg':
    28. return `${dbName}.${dbSchema}`;
    29. case 'mysql':
    30. return dbName;
    31. case 'oracledb':
    32. return _.get(connection.settings, 'username').replace(/"/g, '');
    33. default:
    34. return dbName;
    35. }
    36. };
    1. back-end\h5-api\node_modules\strapi-connector-bookshelf\lib\buildDatabaseSchema.js
    1. const uniqueColName = (table, key) => generateCombinedName('unique', table, key); //`${table}_${key}_unique`;
    2. function generateCombinedName(postfix, name, subNames) {
    3. const crypto = require('crypto');
    4. const limit = 30;
    5. if (!Array.isArray(subNames)) subNames = subNames ? [subNames] : [];
    6. const table = name.replace(/\.|-/g, '_');
    7. const subNamesPart = subNames.join('_');
    8. let result = `${table}_${
    9. subNamesPart.length ? subNamesPart + '_' : ''
    10. }${postfix}`.toLowerCase();
    11. if (result.length > limit) {
    12. console.log(
    13. `Automatically generated name "${result}" exceeds ${limit} character ` +
    14. `limit for Oracle. Using base64 encoded sha1 of that name instead.`
    15. );
    16. // generates the sha1 of the name and encode it with base64
    17. result = crypto
    18. .createHash('sha1')
    19. .update(result)
    20. .digest('base64')
    21. .replace('=', '');
    22. }
    23. return result;
    24. }