1
0
mirror of https://github.com/lana-k/sqliteviz.git synced 2025-12-06 18:18:53 +08:00

move tests to tests folder

rename util modules
rename DbUpload to DbUploader
add tests for DbUploader component #27
This commit is contained in:
lana-k
2021-04-21 11:05:56 +02:00
parent edd45b317a
commit 803622f18f
44 changed files with 333 additions and 157 deletions

44
src/db.utils.js Normal file
View File

@@ -0,0 +1,44 @@
export default {
* generateChunks (arr, size) {
const count = Math.ceil(arr.length / size)
for (let i = 0; i <= count - 1; i++) {
const start = size * i
const end = start + size
yield arr.slice(start, end)
}
},
getInsertStmt (columns) {
const colList = `"${columns.join('", "')}"`
const params = columns.map(() => '?').join(', ')
return `INSERT INTO csv_import (${colList}) VALUES (${params});`
},
getCreateStatement (columns, values) {
let result = 'CREATE table csv_import('
columns.forEach((col, index) => {
// Get the first row of values to determine types
const value = values[0][index]
let type = ''
switch (typeof value) {
case 'number': {
type = 'REAL'
break
}
case 'boolean': {
type = 'INTEGER'
break
}
case 'string': {
type = 'TEXT'
break
}
default: type = 'TEXT'
}
result += `"${col}" ${type}, `
})
result = result.replace(/,\s$/, ');')
return result
}
}