1.0.2 • Published 4 years ago

sqljs-table-loader v1.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

SQL.js TableLoader

Build Status Test Coverage Maintainability

excel/csv file loader for SQL.js.

Usage

in Node.js

$ npm install sqljs-table-loader
import fs from 'fs';
import initSqlJs from 'sql.js';
import TableLoader from 'sqljs-table-loader';


const data = fs.readFileSync(__dirname + '/file.xlsx');
const loader = new TableLoader(data, {/* options (see below) */});

initSqlJs(sql => {
	const db = new sql.Database();

	console.log(loader.sheets);  // view sheet names included in excel file
	console.log(loader.read({/* override options (see below) */}));  // view table data

	loader.importInto(db, 'target_table', {/* override options (see below) */});  // create table and import data

	console.log(db.exec('SELECT * FROM target_table'));
});

in browser

<script src="https://unpkg.com/xlsx"></script>  <!-- required -->
<script src="https://unpkg.com/sql.js"></script>  <!-- optional -->
<script src="https://unpkg.com/sqljs-table-loader"></script>  <!-- this library -->
<script>
var loader = new TableLoader('foo,bar\n1,hello\n2,world');

console.log(loader.sheets);
console.log(loader.read());
</script>

Options

namedefaultdescription
skip_row0Skip first rows
use_headertrueUse first row as column names
sheetnullSheet name to load (if null, load first)
delimiter','The delimiter for csv (only for constructor)
1.0.2

4 years ago

1.0.1

5 years ago

0.0.0

5 years ago