
// Execute raw SQL statement for GraphQL using a custom interface. (Can be re-generated.)
<%- tplTsOnly([`import { App } from '../../app.interface'${sc}`, '']) -%>
<%- insertFragment('imports') %>
<%- insertFragment('init') %>

// <%- lintDisableNextLineUnused %>
<%- tplModuleExports(null, 'function sqlExecuteCustom(app) {', 'function sqlExecuteCustom(app: App) {') %>
  <%- insertFragment('func_custom') %>
  <%- insertFragment('func_dialect', [
    `  // ${lintDisableNextLineUnused}`,
    `  let dialect${tplTsOnly(": 'sqlite3' | 'mariadb' | 'mysql' | 'pg' | 'oracle'")} = null${sc}`,
    '  if (!dialect) {',
    `    throw new Error('Unsupported Custom dialect: \\'' + dialect + '\\'. (sql.execute.custom.*s)')${sc}`,
    '  }',
  ]) %>
  <%- insertFragment('func_init') %>

  // An async function that takes an SQL statement queries a database and resolves to an array of objects
  <%- insertFragment('func_exec', [
    `  // ${lintDisableNextLineUnused}`,
    `  async function executeSql${tplJsOrTs('(sql)', '(sql: string): Promise<any[]>')} {`,
    `    throw new Error('No function for GraphQL SQL execution provided. You need to provide one in ' + __filename)${sc}`,
    `    // ${lintDisableNextLine}`,
    `    return []${sc}`,
    `  }`,
  ]) %>

  let returns = {
    dialect,
    executeSql,
    openDb: undefined
    <%- insertFragment('moduleExports') %>
  }<%- sc %>

  <%- insertFragment('func_return') %>
  return returns<%- sc %>
}<%- sc %>
<%- insertFragment('more') %>

<%- insertFragment('exports') %>
<%- `${tplExport('moduleExports')}${sc}` %>

<%- insertFragment('funcs') %>
<%- insertFragment('end') %>
