index.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. 'use strict';
  2. exports.__esModule = true;
  3. var _defineProperties = require('babel-runtime/core-js/object/define-properties');
  4. var _defineProperties2 = _interopRequireDefault(_defineProperties);
  5. var _assign2 = require('lodash/assign');
  6. var _assign3 = _interopRequireDefault(_assign2);
  7. exports.default = Knex;
  8. var _raw = require('./raw');
  9. var _raw2 = _interopRequireDefault(_raw);
  10. var _helpers = require('./helpers');
  11. var _client = require('./client');
  12. var _client2 = _interopRequireDefault(_client);
  13. var _makeKnex = require('./util/make-knex');
  14. var _makeKnex2 = _interopRequireDefault(_makeKnex);
  15. var _parseConnection = require('./util/parse-connection');
  16. var _parseConnection2 = _interopRequireDefault(_parseConnection);
  17. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  18. // The client names we'll allow in the `{name: lib}` pairing.
  19. var aliases = {
  20. 'mariadb': 'maria',
  21. 'mariasql': 'maria',
  22. 'pg': 'postgres',
  23. 'postgresql': 'postgres',
  24. 'sqlite': 'sqlite3'
  25. };
  26. function Knex(config) {
  27. if (typeof config === 'string') {
  28. return new Knex((0, _assign3.default)((0, _parseConnection2.default)(config), arguments[2]));
  29. }
  30. var Dialect = void 0;
  31. if (arguments.length === 0 || !config.client && !config.dialect) {
  32. Dialect = _client2.default;
  33. } else if (typeof config.client === 'function' && config.client.prototype instanceof _client2.default) {
  34. Dialect = config.client;
  35. } else {
  36. var clientName = config.client || config.dialect;
  37. Dialect = require('./dialects/' + (aliases[clientName] || clientName) + '/index.js');
  38. }
  39. if (typeof config.connection === 'string') {
  40. config = (0, _assign3.default)({}, config, { connection: (0, _parseConnection2.default)(config.connection).connection });
  41. }
  42. return (0, _makeKnex2.default)(new Dialect(config));
  43. }
  44. // Expose Client on the main Knex namespace.
  45. Knex.Client = _client2.default;
  46. (0, _defineProperties2.default)(Knex, {
  47. VERSION: {
  48. get: function get() {
  49. (0, _helpers.warn)('Knex.VERSION is deprecated, you can get the module version' + "by running require('knex/package').version");
  50. return '0.12.6';
  51. }
  52. },
  53. Promise: {
  54. get: function get() {
  55. (0, _helpers.warn)('Knex.Promise is deprecated, either require bluebird or use the global Promise');
  56. return require('bluebird');
  57. }
  58. }
  59. });
  60. // Run a "raw" query, though we can't do anything with it other than put
  61. // it in a query statement.
  62. Knex.raw = function (sql, bindings) {
  63. (0, _helpers.warn)('global Knex.raw is deprecated, use knex.raw (chain off an initialized knex object)');
  64. return new _raw2.default().set(sql, bindings);
  65. };
  66. // Doing this ensures Browserify works. Still need to figure out
  67. // the best way to do some of this.
  68. if (process.browser) {
  69. require('./dialects/websql/index.js');
  70. }
  71. module.exports = exports['default'];