<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Source: drivers/Sqlite.js</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Source: drivers/Sqlite.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>/** * Driver for SQLite databases * * @module drivers/Sqlite */ module.exports = (() => { delete require.cache[require.resolve('../Driver')]; const driver = require('../Driver'); // Sqlite doesn't have a truncate command driver.hasTruncate = false; /** * SQL to insert a group of rows * Override default to have better compatibility * * @param {String} table - The table to insert to * @param {Array} [data] - The array of object containing data to insert * @return {String} - The generated sql statement */ driver.insertBatch = (table, data) => { // Get the data values to insert, so they can // be parameterized let sql = ''; const first = data.shift(); const vals = []; data.forEach(obj => { const row = []; Object.keys(obj).forEach(key => { row.push(obj[key]); }); vals.push(row); }); sql += `INSERT INTO ${driver.quoteTable(table)}\n`; // Get the field names from the keys of the first // object to be inserted const fields = Object.keys(first); const cols = []; fields.forEach(key => { cols.push(`'${driver._quote(first[key])}' AS ${driver.quoteIdentifiers(key)}`); }); sql += `SELECT ${cols.join(', ')}\n`; vals.forEach(rowValues => { const quoted = rowValues.map(value => String(value).replace('\'', '\'\'')); sql += `UNION ALL SELECT '${quoted.join('\', \'')}'\n`; }); return { sql: sql, values: undefined }; }; return driver; })(); </code></pre> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-drivers_MariaDB.html">drivers/MariaDB</a></li><li><a href="module-drivers_MSSQLDriver.html">drivers/MSSQLDriver</a></li><li><a href="module-drivers_Mysql.html">drivers/Mysql</a></li><li><a href="module-drivers_Pg.html">drivers/Pg</a></li><li><a href="module-drivers_Sqlite.html">drivers/Sqlite</a></li></ul><h3>Classes</h3><ul><li><a href="NodeQuery.html">NodeQuery</a></li><li><a href="QueryBuilder.html">QueryBuilder</a></li><li><a href="Result.html">Result</a></li></ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Mon Feb 12 2018 14:58:25 GMT-0500 (EST) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>