Skip to content

Functions:SQL

Emiel Wit edited this page Nov 16, 2022 · 12 revisions

SQL [BETA]

With the sql helper, pro-coders can connect with an external database and execute raw SQL.

The sql helper accepts the following arguments:

interface DBCredentials {
  host: string;
  port: number;
  user: string;
  password: string;
  database: string;
}

interface Options {
  client?: string; // default mysql
  raw: string;
  timeout?: number; // default 20s
}

const result = await queryMsSQL(credentials: DBCredentials, options: Options);

This helper makes use of KnexJS. We accept the following database libraries:

  • pg
  • mysql
  • mysql2
  • oracledb
  • tedious

For more information check the following link: Installation | Knex.js.

Example function:

const queryMsSQL = async () => {
  const result = await sql(
    {
      host: '127.0.0.1',
      port: 3306,
      user: 'your_database_user',
      password: 'your_database_password',
      database: 'myapp_test',
    },
    {
      raw: 'SELECT * FROM empDepartment;',
      client: 'mssql',
    }
  );

  return {
    result,
  };
};

export default msSQLConnection;
Clone this wiki locally