diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c50c06..39fb5a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 0.24.0 (2025-02-05) +- Better column names! Now non-latin characters are being romanised so you can access your properties (and other column names) easier: geändert becomes geandert, 类别 becomes lei_bie, ノートタイプ becomes nototaipu, etc. + # 0.23.2 (2025-02-04) - No longer captalising renderer options (it was breaking SQLSeal Charts integration) diff --git a/manifest.json b/manifest.json index e1f98ac..6983ac8 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "sqlseal", "name": "SQLSeal", - "version": "0.23.2", + "version": "0.24.0", "minAppVersion": "0.15.0", "description": "Use SQL in your notes to query your vault files and CSV content.", "author": "hypersphere", diff --git a/package.json b/package.json index f7be772..167b042 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sqlseal", - "version": "0.23.2", + "version": "0.24.0", "description": "A plugin for Obsidian that allows you to run SQL queries on your notes.", "main": "main.js", "scripts": { @@ -15,7 +15,12 @@ "docs:preview": "vitepress preview docs", "test": "jest" }, - "keywords": ["Obsidian", "SQLite", "note-taking", "TypeScript"], + "keywords": [ + "Obsidian", + "SQLite", + "note-taking", + "TypeScript" + ], "author": "", "license": "MIT", "devDependencies": { @@ -58,6 +63,7 @@ "markdown-table-ts": "^1.0.3", "papaparse": "^5.4.1", "sql-parser-cst": "^0.32.0", + "unidecode": "^1.1.0", "util": "^0.12.5", "uuid": "^11.0.4" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6d54463..8aac7b1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -62,6 +62,9 @@ importers: sql-parser-cst: specifier: ^0.32.0 version: 0.32.0 + unidecode: + specifier: ^1.1.0 + version: 1.1.0 util: specifier: ^0.12.5 version: 0.12.5 @@ -3087,6 +3090,10 @@ packages: undici-types@6.19.8: resolution: {integrity: sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==} + unidecode@1.1.0: + resolution: {integrity: sha512-GIp57N6DVVJi8dpeIU6/leJGdv7W65ZSXFLFiNmxvexXkc0nXdqUvhA/qL9KqBKsILxMwg5MnmYNOIDJLb5JVA==} + engines: {node: '>= 0.4.12'} + unique-filename@2.0.1: resolution: {integrity: sha512-ODWHtkkdx3IAR+veKxFV+VBkUMcN+FaqzUUd7IZzt+0zhDZFPFxhlqwPF3YQvMHx1TD0tdgYl+kuPnJ8E6ql7A==} engines: {node: ^12.13.0 || ^14.15.0 || >=16.0.0} @@ -6600,6 +6607,8 @@ snapshots: undici-types@6.19.8: {} + unidecode@1.1.0: {} + unique-filename@2.0.1: dependencies: unique-slug: 3.0.0 diff --git a/src/sql/sqlTransformer.ts b/src/sql/sqlTransformer.ts index a3ef65e..a2d456b 100644 --- a/src/sql/sqlTransformer.ts +++ b/src/sql/sqlTransformer.ts @@ -1,5 +1,5 @@ import { uniq } from 'lodash'; -import { parse, show, Node, cstVisitor } from 'sql-parser-cst'; +import { parse, show, cstVisitor } from 'sql-parser-cst'; /** * Function transforms SQL query and updates tables into actual names in te database. diff --git a/src/utils/sanitiseColumn.test.ts b/src/utils/sanitiseColumn.test.ts new file mode 100644 index 0000000..1a4748a --- /dev/null +++ b/src/utils/sanitiseColumn.test.ts @@ -0,0 +1,30 @@ +import { sanitise } from "./sanitiseColumn" + +describe('sanitise', () => { + it('should sanitise spaces and special characters', () => { + expect(sanitise('distance (km2)')).toEqual('distance__km2_') + expect(sanitise('is new?')).toEqual('is_new_') + expect(sanitise('view-as')).toEqual('view_as') + }) + + it('should sanitise reserved keywords', () => { + expect(sanitise('BEGIN')).toEqual('begin_') + expect(sanitise('AS')).toEqual('as_') + expect(sanitise('BEGIN AS')).toEqual('begin_as') + }) + + it('should properly normalise non-latin characters', () => { + expect(sanitise('ćwiczenia')).toEqual('cwiczenia') + expect(sanitise('część')).toEqual('czesc') + expect(sanitise('geändert')).toEqual('geandert') + expect(sanitise('หมวดหมู่')).toEqual('hmwdhmuu') + expect(sanitise('类别')).toEqual('lei_bie') + expect(sanitise('категория')).toEqual('kategoriia') + expect(sanitise('カテゴリ')).toEqual('kategori') + expect(sanitise('ノートタイプ')).toEqual('nototaipu') + expect(sanitise('نوع یادداشت')).toEqual('nw__yddsht') + expect(sanitise('סוג הערה')).toEqual('svg_h_rh') + expect(sanitise('नोट प्रकार')).toEqual('nott_prkaar') + expect(sanitise('kožušček')).toEqual('kozuscek') + }) +}) \ No newline at end of file diff --git a/src/utils/sanitiseColumn.ts b/src/utils/sanitiseColumn.ts index e1da8ae..aae6353 100644 --- a/src/utils/sanitiseColumn.ts +++ b/src/utils/sanitiseColumn.ts @@ -1,3 +1,5 @@ +const unidecode = require('unidecode') + /** * Sanitizes a string to be used as a valid SQLite column name. * Rules implemented: @@ -35,8 +37,10 @@ export function sanitise(input: string): string { return '_empty'; } + const nonAccented = unidecode(input).trim() + // Replace any character that isn't a letter, number, or underscore with underscore - let sanitized = input.replace(/[^a-zA-Z0-9_]/g, '_'); + let sanitized = nonAccented.replace(/[^a-zA-Z0-9_]/g, '_'); // Ensure it starts with a letter or underscore if (!/^[a-zA-Z_]/.test(sanitized)) { diff --git a/versions.json b/versions.json index 04d3c52..771dddf 100644 --- a/versions.json +++ b/versions.json @@ -42,5 +42,6 @@ "0.22.3": "0.15.0", "0.23.0": "0.15.0", "0.23.1": "0.15.0", - "0.23.2": "0.15.0" + "0.23.2": "0.15.0", + "0.24.0": "0.15.0" } \ No newline at end of file