(2.) Then I use `typeof` operator for each field to determine appropriate javascript type.
(3.) Then, I map these javascript types to sqlite types using this mapping:::
const typeMapping = { 'number': 'REAL', 'string': 'TEXT', 'boolean': 'INTEGER', 'object': 'TEXT', 'undefined': 'TEXT' };
(4.) Then, I generate create table sql's fields declaration part. This also handles an edge case where if first 1000 rows (used for schema generation) of a particular field are all null/undefined, I default to using sqlite's TEXT type using this:::
const columns = fields.map(field => `'${field}' ${typeMapping[columnTypes[field]] || 'TEXT'}`);
(5.) Finally, I create sqlite table:::
const createTableSQL = `CREATE TABLE data (${columns.join(', ')});`;
db = new SQL.Database();
db.run(createTableSQL);
Thanks..