mirror of
https://github.com/h-sphere/sql-seal.git
synced 2026-07-22 10:10:28 +00:00
Merge pull request #15 from h-sphere/feat/grid-improvements
chore: fixing updates and adding checkboxes
This commit is contained in:
commit
5f7c3107c3
7 changed files with 68 additions and 31 deletions
|
|
@ -1,3 +1,7 @@
|
|||
# 0.9.2
|
||||
Adding checkbox method to display boolean values as checkboxes
|
||||
Fixing how updates are parsed
|
||||
|
||||
# 0.9.1
|
||||
Turning off verbose mode
|
||||
# 0.9.0
|
||||
|
|
|
|||
|
|
@ -50,4 +50,10 @@ WHERE authors LIKE concat('%', @author, '%')
|
|||
LIMIT 10
|
||||
```
|
||||
|
||||

|
||||

|
||||
|
||||
## Checkboxes
|
||||
You can display boolean data as checkbox in the interface by calling `checkbox` function:
|
||||
```sql
|
||||
SELECT date, checkbox(excercised) FROM files WHERE date is not null
|
||||
```
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "sqlseal",
|
||||
"name": "SQLSeal",
|
||||
"version": "0.9.1",
|
||||
"version": "0.9.2",
|
||||
"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.9.1",
|
||||
"version": "0.9.2",
|
||||
"description": "A plugin for Obsidian that allows you to run SQL queries on your notes.",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
|
|
|
|||
|
|
@ -14,6 +14,33 @@ export interface FieldDefinition {
|
|||
type: FieldTypes
|
||||
}
|
||||
|
||||
const formatData = (data: Record<string, any>) => {
|
||||
return Object.keys(data).reduce((ret, key) => {
|
||||
if (typeof data[key] === 'boolean') {
|
||||
return {
|
||||
...ret,
|
||||
[key]: data[key] ? 1 : 0
|
||||
}
|
||||
}
|
||||
if (!data[key]) {
|
||||
return {
|
||||
...ret,
|
||||
[key]: null
|
||||
}
|
||||
}
|
||||
if (typeof data[key] === 'object' || Array.isArray(data[key])) {
|
||||
return {
|
||||
...ret,
|
||||
[key]: JSON.stringify(data[key])
|
||||
}
|
||||
}
|
||||
return {
|
||||
...ret,
|
||||
[key]: data[key]
|
||||
}
|
||||
}, {})
|
||||
}
|
||||
|
||||
export class SqlSealDatabase {
|
||||
private savedDatabases: Record<string, any> = {}
|
||||
db: Database.Database
|
||||
|
|
@ -112,6 +139,14 @@ export class SqlSealDatabase {
|
|||
return `SQLSEALCUSTOM(${JSON.stringify(imgObject)})`
|
||||
})
|
||||
|
||||
this.db.function('checkbox', (val: string) => {
|
||||
const imgObject = {
|
||||
type: 'checkbox',
|
||||
value: val
|
||||
}
|
||||
return `SQLSEALCUSTOM(${JSON.stringify(imgObject)})`
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
async disconect() {
|
||||
|
|
@ -151,7 +186,7 @@ export class SqlSealDatabase {
|
|||
const updateMany = this.db.transaction((pData: Array<Record<string, any>>) => {
|
||||
pData.forEach(data => {
|
||||
try {
|
||||
update.run(data)
|
||||
update.run(formatData(data))
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
|
|
@ -183,30 +218,7 @@ export class SqlSealDatabase {
|
|||
pData.forEach(data => {
|
||||
const columns = Object.keys(data)
|
||||
const insert = this.db.prepare(`INSERT INTO ${name} (${columns.join(', ')}) VALUES (${columns.map((key: string) => '@' + key).join(', ')})`);
|
||||
const d = Object.keys(data).reduce((ret, key) => {
|
||||
if (typeof data[key] === 'boolean') {
|
||||
return {
|
||||
...ret,
|
||||
[key]: data[key] ? 1 : 0
|
||||
}
|
||||
}
|
||||
if (!data[key]) {
|
||||
return {
|
||||
...ret,
|
||||
[key]: null
|
||||
}
|
||||
}
|
||||
if (typeof data[key] === 'object' || Array.isArray(data[key])) {
|
||||
return {
|
||||
...ret,
|
||||
[key]: JSON.stringify(data[key])
|
||||
}
|
||||
}
|
||||
return {
|
||||
...ret,
|
||||
[key]: data[key]
|
||||
}
|
||||
}, {})
|
||||
const d = formatData(data)
|
||||
insert.run(d)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
18
src/ui.ts
18
src/ui.ts
|
|
@ -32,7 +32,11 @@ export const displayData = (el: HTMLElement, columns: string[], data: Array<Reco
|
|||
rowData: data,
|
||||
columnDefs: columns.map(c => ({
|
||||
field: c,
|
||||
cellRenderer: ({ value }: { value: string }) => parseCell(value, app),
|
||||
cellRendererSelector: (data) => {
|
||||
return {
|
||||
component: ({ value }: { value: string }) => parseCell(value, app)
|
||||
}
|
||||
},
|
||||
autoHeight: true
|
||||
})),
|
||||
domLayout: 'autoHeight'
|
||||
|
|
@ -86,7 +90,12 @@ type SQLSealImgElement = {
|
|||
href: string
|
||||
}
|
||||
|
||||
type SqlSealCustomElement = SqlSealAnchorElement | SQLSealImgElement;
|
||||
type SQLSealCheckboxElement = {
|
||||
type: 'checkbox',
|
||||
value: number
|
||||
}
|
||||
|
||||
type SqlSealCustomElement = SqlSealAnchorElement | SQLSealImgElement | SQLSealCheckboxElement;
|
||||
|
||||
const isLinkLocal = (link: string) => !link?.trim().startsWith('http')
|
||||
|
||||
|
|
@ -143,6 +152,11 @@ const renderSqlSealCustomElement = (customConfig: SqlSealCustomElement, app: App
|
|||
return 'File does not exist'
|
||||
}
|
||||
return createEl('img', { attr: { src: app.vault.getResourcePath(file) } });
|
||||
case 'checkbox':
|
||||
const el = createEl('input', { type: 'checkbox' })
|
||||
el.checked = !!customConfig.value
|
||||
el.disabled = true
|
||||
return el
|
||||
default:
|
||||
return 'Invalid Custom Element'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,5 +9,6 @@
|
|||
"0.7.0": "0.15.0",
|
||||
"0.8.0": "0.15.0",
|
||||
"0.9.0": "0.15.0",
|
||||
"0.9.1": "0.15.0"
|
||||
"0.9.1": "0.15.0",
|
||||
"0.9.2": "0.15.0"
|
||||
}
|
||||
Loading…
Reference in a new issue