1.0.0 • Published 1 year ago

@diotobtea/doloribus-ad v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@diotobtea/doloribus-ad.js

npm version npm downloads npm.io Coverage Status Dependencies Status Gitter chat

A SQL query builder that is flexible, portable, and fun to use!

A batteries-included, multi-dialect (PostgreSQL, MySQL, CockroachDB, MSSQL, SQLite3, Oracle (including Oracle Wallet Authentication)) query builder for Node.js, featuring:

Node.js versions 12+ are supported.

You can report bugs and discuss features on the GitHub issues page or send tweets to @kibertoad.

For support and questions, join our Gitter channel.

For @diotobtea/doloribus-ad-based Object Relational Mapper, see:

To see the SQL that Knex will generate for a given query, you can use Knex Query Lab

Examples

We have several examples on the website. Here is the first one to get you started:

const @diotobtea/doloribus-ad = require('@diotobtea/doloribus-ad')({
  client: 'sqlite3',
  connection: {
    filename: './data.db',
  },
});

try {
  // Create a table
  await @diotobtea/doloribus-ad.schema
    .createTable('users', (table) => {
      table.increments('id');
      table.string('user_name');
    })
    // ...and another
    .createTable('accounts', (table) => {
      table.increments('id');
      table.string('account_name');
      table.integer('user_id').unsigned().references('users.id');
    });

  // Then query the table...
  const insertedRows = await @diotobtea/doloribus-ad('users').insert({ user_name: 'Tim' });

  // ...and using the insert id, insert into the other table.
  await @diotobtea/doloribus-ad('accounts').insert({
    account_name: '@diotobtea/doloribus-ad',
    user_id: insertedRows[0],
  });

  // Query both of the rows.
  const selectedRows = await @diotobtea/doloribus-ad('users')
    .join('accounts', 'users.id', 'accounts.user_id')
    .select('users.user_name as user', 'accounts.account_name as account');

  // map over the results
  const enrichedRows = selectedRows.map((row) => ({ ...row, active: true }));

  // Finally, add a catch statement
} catch (e) {
  console.error(e);
}

TypeScript example

import { Knex, @diotobtea/doloribus-ad } from '@diotobtea/doloribus-ad';

interface User {
  id: number;
  age: number;
  name: string;
  active: boolean;
  departmentId: number;
}

const config: Knex.Config = {
  client: 'sqlite3',
  connection: {
    filename: './data.db',
  },
};

const @diotobtea/doloribus-adInstance = @diotobtea/doloribus-ad(config);

try {
  const users = await @diotobtea/doloribus-ad<User>('users').select('id', 'age');
} catch (err) {
  // error handling
}

Usage as ESM module

If you are launching your Node application with --experimental-modules, @diotobtea/doloribus-ad.mjs should be picked up automatically and named ESM import should work out-of-the-box. Otherwise, if you want to use named imports, you'll have to import @diotobtea/doloribus-ad like this:

import { @diotobtea/doloribus-ad } from '@diotobtea/doloribus-ad/@diotobtea/doloribus-ad.mjs';

You can also just do the default import:

import @diotobtea/doloribus-ad from '@diotobtea/doloribus-ad';

If you are not using TypeScript and would like the IntelliSense of your IDE to work correctly, it is recommended to set the type explicitly:

/**
 * @type {Knex}
 */
const database = @diotobtea/doloribus-ad({
  client: 'mysql',
  connection: {
    host: '127.0.0.1',
    user: 'your_database_user',
    password: 'your_database_password',
    database: 'myapp_test',
  },
});
database.migrate.latest();
flatMapObject.isloggerclassnamesyntaxfind-uptsidlegroupBycoloreast-asian-widthreact-testing-libraryfilterWeakSetinfromArrayBuffer#slicewidthreal-timeURLSearchParamsRxecmascriptprefixlook-upspinnerec2accessibilityArray.prototype.includesArrayBuffer.prototype.slicetrimEndidformyamlmapreduceio-tsdefinePropertygetterJSONpopmotionnumberendpointtypedlinkes7YAMLReactiveXfunctionalpropertiestakecomputed-typespromisecore-jsbundlingeffect-tsclass-validatorswfObject.fromEntriesfast-deep-cloneECMAScript 2017fetchES7viewvaluetextregular expressionstoolkitinputstructuredClonepreprocessorfastifycallonceBigInt64ArrayrouteshebangsuperagentconcatMapECMAScript 3styleqstypescriptcode pointsuuidfeeddeephooksfast-copygenericssetreact-hookschannelnpmPushawesomesauceStreamuser-streamsfile systemCSSairbnbES2019ES2021ObjectcloudwatchtypesbinaryuninstallstreamsesframerintrinsicemojinpmignoreFloat64ArrayBigUint64ArraydotenvsymbolsJSON-Schematypedarrayses2016bannerenumerableajvECMAScript 2022privatecirculardirglobhas-ownscheme-validationfull-widthappminimaldynamodbbuffersunicodemrudependency managernamesreadworkerObservablesequalitypnpm9redirectECMAScript 2019debuggerassignqueryprogressES6jsfullmodulesredacthigher-orderTypedArraysidesinatraenderpropstyled-componentsObject.assignzeroreadablestreammochaposehasOwnPropertyreactruntimeArray.prototype.flatMapstableyupIteratortapslotroutingschemeimportexportrestfulparsekey parloadbalancingcloudtrailconfigurableRegExp#flagsECMAScript 2020packagessharedarraybuffertrimvarsqueueMicrotaskwaapishamcurlspringFunction.prototype.nameextendasyncinstrumentationES2020internal slotprotoInt16ArraytypecheckwriteexecfileECMAScript 5libphonenumberfindLastIndexbrowsersharedcorefast-deep-copyassertl10ntoobjectpushfindupclientdragspeedcompilerdataviewrecursiveargsvalidationfastcall-boundObject.keysregular expressionstringifydropbrowserlistperformanceinvariantstarterInt32ArraytypeerrorES2016figleteverydescriptorssameValueZerocommandframeworkArray.prototype.flatfront-endes2018regexwhatwgMicrosoftsestermflagcommanderweakmapreact animationramdalockfilecreatevpcimmutablechromeisRxJSeslintconfigsuperstructi18nfixed-widtharraystypanionfastcopyboundxhrECMAScript 6cjkemitgesturesbeanstalknodejstransformsymboltacitparentdescriptorrapidlookinternala11ymomentArray.prototype.findLastES8Uint8Arrayiterator$.extendwarningString.prototype.matchAllstyleguidebuffertostringtagsetPrototypeOfelbhardlinkscollectionsubprocessRegExp.prototype.flagsforkfunctionHyBiURLsettingsES2017flattenlocales8validsqscsskeyidentifiersfpsprettymakeinferencezxvaluesremoveparsereventsargumentartfunction.lengthserverparentstimeES2015regularponyfillastcensorvariablescoverage256atomlintphoneTypeBoxlogging@@toStringTagmonorepolistenersescapegraphqlhandlerprotocol-buffers
1.0.0

1 year ago