mirror of
https://github.com/h-sphere/sql-seal.git
synced 2026-07-22 10:10:28 +00:00
Merge pull request #30 from h-sphere/fix/fix-casing-and-csv-import
fix: fixing issue with SELECT casing and edge-case when loading data
This commit is contained in:
commit
4dd84294b3
8 changed files with 59 additions and 31 deletions
|
|
@ -1,3 +1,7 @@
|
|||
# 0.14.1
|
||||
fix: fixed the issue where rows with extra data in them (rows with more columns that a header) were not synchronised correctly
|
||||
fix: fixed the issue where queries with lowercase SELECT would not work in certain cases.
|
||||
|
||||
# 0.14.0
|
||||
Added support for inline code blocks. Create a codeblock (backtick `) and use prefix S> to indicate it's SQLSeal query.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "sqlseal",
|
||||
"name": "SQLSeal",
|
||||
"version": "0.14.0",
|
||||
"version": "0.14.1",
|
||||
"minAppVersion": "0.15.0",
|
||||
"description": "Use SQL in your notes to query your vault files and CSV content.",
|
||||
"author": "hypersphere",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "sqlseal",
|
||||
"version": "0.14.0",
|
||||
"version": "0.14.1",
|
||||
"description": "A plugin for Obsidian that allows you to run SQL queries on your notes.",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ export class WorkerDatabase {
|
|||
|
||||
async insertData(tableName: string, data: Record<string, unknown>[]) {
|
||||
data.forEach(d => {
|
||||
const columns = Object.keys(d)
|
||||
const columns = Object.keys(d).filter(c => c !== '__parsed_extra')
|
||||
const insertStatement = this.db.prepare(`INSERT INTO ${tableName} (${columns.join(', ')}) VALUES (${columns.map((key: string) => '@' + key).join(', ')})`);
|
||||
insertStatement.run(recordToBindParams(formatData(d)))
|
||||
})
|
||||
|
|
|
|||
|
|
@ -80,11 +80,13 @@ export class Sync {
|
|||
skipEmptyLines: true,
|
||||
transformHeader: sanitise
|
||||
})
|
||||
console.log('PARSED', parsed)
|
||||
const typeStatements = toTypeStatements(parsed.meta.fields ?? [], parsed.data)
|
||||
const columns = Object.entries(typeStatements.types).map(([key, value]) => ({
|
||||
name: key,
|
||||
type: value as FieldTypes
|
||||
}));
|
||||
console.log('COLUMNZ', columns)
|
||||
const tableName = entry.table_name
|
||||
await this.db.createTableClean(tableName, columns)
|
||||
await this.db.insertData(tableName, typeStatements.data)
|
||||
|
|
|
|||
|
|
@ -56,7 +56,8 @@ export function parseLanguage(input: string): ParsedLanguage {
|
|||
// Find the position of SELECT statement
|
||||
let selectPosition = -1;
|
||||
for (let i = currentPosition; i < lines.length; i++) {
|
||||
if (lines[i].trim().startsWith('SELECT') || lines[i].trim().startsWith('WITH')) {
|
||||
const line = lines[i].trim().toUpperCase()
|
||||
if (line.startsWith('SELECT') || line.startsWith('WITH')) {
|
||||
selectPosition = i;
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,13 +14,13 @@ describe('Parser', () => {
|
|||
it('should parse properly table and select', () => {
|
||||
expect(parseLanguage(`TABLE x = file(a.csv)
|
||||
SELECT * FROM files`)).toEqual({
|
||||
tables: [{
|
||||
tableName: 'x',
|
||||
fileName: 'a.csv'
|
||||
}],
|
||||
queryPart: 'SELECT * FROM files',
|
||||
intermediateContent: ''
|
||||
})
|
||||
tables: [{
|
||||
tableName: 'x',
|
||||
fileName: 'a.csv'
|
||||
}],
|
||||
queryPart: 'SELECT * FROM files',
|
||||
intermediateContent: ''
|
||||
})
|
||||
})
|
||||
|
||||
it('should parse properly multiple tables in the same file', () => {
|
||||
|
|
@ -31,17 +31,17 @@ SELECT * FROM a JOIN y ON a.id=y.id`)).toEqual({
|
|||
tableName: 'x',
|
||||
fileName: 'a.csv'
|
||||
},
|
||||
{
|
||||
tableName: 'y',
|
||||
fileName: 'very-long-name.csv'
|
||||
}],
|
||||
{
|
||||
tableName: 'y',
|
||||
fileName: 'very-long-name.csv'
|
||||
}],
|
||||
queryPart: 'SELECT * FROM a JOIN y ON a.id=y.id',
|
||||
intermediateContent: ''
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('should parse properly multiple tables in the same file', () => {
|
||||
expect(parseLanguage(`TABLE x = file(a.csv)
|
||||
it('should parse properly multiple tables in the same file', () => {
|
||||
expect(parseLanguage(`TABLE x = file(a.csv)
|
||||
TABLE y = file(very-long-name.csv)
|
||||
|
||||
PLOT {
|
||||
|
|
@ -49,19 +49,39 @@ PLOT {
|
|||
y: 654
|
||||
}
|
||||
SELECT * FROM a JOIN y ON a.id=y.id`)).toEqual({
|
||||
tables: [{
|
||||
tableName: 'x',
|
||||
fileName: 'a.csv'
|
||||
},
|
||||
{
|
||||
tableName: 'y',
|
||||
fileName: 'very-long-name.csv'
|
||||
}],
|
||||
queryPart: 'SELECT * FROM a JOIN y ON a.id=y.id',
|
||||
intermediateContent: `PLOT {
|
||||
tables: [{
|
||||
tableName: 'x',
|
||||
fileName: 'a.csv'
|
||||
},
|
||||
{
|
||||
tableName: 'y',
|
||||
fileName: 'very-long-name.csv'
|
||||
}],
|
||||
queryPart: 'SELECT * FROM a JOIN y ON a.id=y.id',
|
||||
intermediateContent: `PLOT {
|
||||
x: 5,
|
||||
y: 654
|
||||
}`
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('should properly parse query where SELECT is lowercase', () => {
|
||||
expect(parseLanguage(`
|
||||
HTML
|
||||
select * from files`)).toEqual({
|
||||
"intermediateContent": "HTML",
|
||||
"queryPart": "select * from files",
|
||||
"tables": [],
|
||||
})
|
||||
})
|
||||
|
||||
it('should properly parse query where SELECT is in sPoNgeBoB-cAsE', () => {
|
||||
expect(parseLanguage(`
|
||||
HTML
|
||||
sElEcT * fRoM files`)).toEqual({
|
||||
"intermediateContent": "HTML",
|
||||
"queryPart": "sElEcT * fRoM files",
|
||||
"tables": [],
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
@ -20,5 +20,6 @@
|
|||
"0.12.3": "0.15.0",
|
||||
"0.12.4": "0.15.0",
|
||||
"0.13.0": "0.15.0",
|
||||
"0.14.0": "0.15.0"
|
||||
"0.14.0": "0.15.0",
|
||||
"0.14.1": "0.15.0"
|
||||
}
|
||||
Loading…
Reference in a new issue