feat: better column names. Romanising all the columns!

This commit is contained in:
Kacper Kula 2025-02-05 14:27:40 +00:00
parent 6f4967ef9b
commit 3cf28ff3cf
8 changed files with 59 additions and 6 deletions

View file

@ -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)

View file

@ -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",

View file

@ -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"
}

View file

@ -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

View file

@ -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.

View file

@ -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')
})
})

View file

@ -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)) {

View file

@ -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"
}