mirror of
https://github.com/h-sphere/sql-seal.git
synced 2026-07-22 10:10:28 +00:00
Merge pull request #98 from h-sphere/feat/exposing-more-file-variables
feat: exposing filename, path and extension
This commit is contained in:
commit
c66b78f88d
4 changed files with 42 additions and 4 deletions
|
|
@ -1,6 +1,7 @@
|
|||
# Unreleased
|
||||
- Added TEMPLATE view that allow to render your template with custom Handlebars template.
|
||||
- Improved syntax highlighting - now lines with errors will get highlighted with appropriate colour to indicate the issue
|
||||
- Added @path, @fileName and @extension variables you can use inside your SQL alongside other Frontmatter properties
|
||||
|
||||
Fixes:
|
||||
- Fixed parsing arguments to the `file` function. Now parameters with symbols like `[]*` should work properly (i.e. JSONPath arguments)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,25 @@
|
|||
# Using properties
|
||||
You can use properties to customise your queries and make them dynamic. This can be helpful if you plan to reuse your queries accross multiple files or use them in the templates.
|
||||
|
||||
You can refer to your properties by prepending them with an `@` symbol, for example `@year` to refer to `year` property.
|
||||
You can refer to your properties by prepending them with an `@` symbol, for example `@year` to refer to `year` property.
|
||||
|
||||
## Built-in variables
|
||||
On top of properties current file exposes in the properties, you can also use the following properties that will automatically get exposed:
|
||||
|
||||
| Property | Description | Sample value |
|
||||
| ---------- | ------------------------------------------- | ---------------- |
|
||||
| @path | Full path of the file you're editing | `folder/file.md` |
|
||||
| @fileName | Filename with extension | `file.md` |
|
||||
| @extension | Extension of the file (without leading dot) | `md` |
|
||||
|
||||
|
||||
### Example 1: Selecting just the current file from the files table
|
||||
|
||||
```sql
|
||||
SELECT * FROM files WHERE path = @path
|
||||
```
|
||||
|
||||
### Example2: Select tags of the current file
|
||||
```sql
|
||||
SELECT * FROM tags WHERE path = @path
|
||||
```
|
||||
|
|
@ -114,7 +114,14 @@ export class CodeblockProcessor extends MarkdownRenderChild {
|
|||
this.explainEl.textContent = result
|
||||
}
|
||||
|
||||
const { data, columns } = await this.db.select(transformedQuery, fileCache?.frontmatter ?? {})
|
||||
const variables = {
|
||||
...fileCache?.frontmatter ?? {},
|
||||
path: file.path,
|
||||
fileName: file.name,
|
||||
extension: file.extension,
|
||||
}
|
||||
|
||||
const { data, columns } = await this.db.select(transformedQuery, variables)
|
||||
this.renderer.render({ data, columns, flags: this.flags })
|
||||
} catch (e) {
|
||||
this.renderer.error(e.toString())
|
||||
|
|
|
|||
|
|
@ -55,9 +55,18 @@ export class InlineProcessor extends MarkdownRenderChild {
|
|||
}
|
||||
|
||||
const fileCache = this.app.metadataCache.getFileCache(file);
|
||||
|
||||
// TODO: unify this between codeblock and inline handlers
|
||||
const variables = {
|
||||
...fileCache?.frontmatter ?? {},
|
||||
path: file.path,
|
||||
fileName: file.name,
|
||||
extension: file.extension,
|
||||
}
|
||||
|
||||
const { data, columns } = await this.db.select(
|
||||
transformedQuery.sql,
|
||||
fileCache?.frontmatter ?? {}
|
||||
transformedQuery.sql,
|
||||
variables
|
||||
);
|
||||
|
||||
this.el.empty()
|
||||
|
|
|
|||
Loading…
Reference in a new issue