Skip to content
This repository has been archived by the owner on Mar 3, 2024. It is now read-only.

Commit

Permalink
chore: stricter tsconfig and README.md edit
Browse files Browse the repository at this point in the history
  • Loading branch information
clouedoc committed Jun 24, 2022
1 parent aa9912e commit 7f1f7b0
Show file tree
Hide file tree
Showing 7 changed files with 272 additions and 225 deletions.
4 changes: 4 additions & 0 deletions .ncurc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"upgrade": true,
"reject": ["@types/node"]
}
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ I personally prefer to self-host PostgreSQL on an offshore server to protect my

I did not try the managed providers that I listed above, but they are from reputable companies and provide way more storage and compute power than you will ever need to host the data generated by this plugin.

### Where is my data stored?

The data produced by `postgresql-obsidian` is made available to you under the `obsidian` database schema.

You can use PostgreSQL views to extract and format the information that you need.

### Why should I send my data to a PostgreSQL database?

Sending the metadata of your notes to a PostgreSQL database will allow you to explore it with other tools, such as [Grafana](https://github.com/grafana/grafana/blob/main/README.md).

Here is a screenshot of the Grafana dashboard I made to monitor my personal health:

![Grafana dashboard of clouedoc's health, made using the data produced by the postgresql-obsidian plugin. It features charts of an ok-ish lifestyle.](./assets/grafana-dashboard.png)

## Contributing

Contributions are what make the open source community such an amazing place to be, learn, inspire, and create. Any contributions you make are **greatly appreciated**!
Expand Down
Binary file added assets/grafana-dashboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"dev": "node esbuild.config.mjs",
"build": "tsc && node esbuild.config.mjs production",
"version": "node version-bump.mjs && git add manifest.json versions.json",
"ncu": "npx npm-check-updates",
"lint": "eslint ./src"
},
"keywords": [
Expand All @@ -20,19 +21,19 @@
"author": "clouedoc",
"license": "MIT",
"devDependencies": {
"@rushstack/eslint-config": "^2.6.0",
"@rushstack/eslint-config": "^2.6.1",
"@types/node": "^16.11.6",
"@types/pg": "^8.6.5",
"@typescript-eslint/eslint-plugin": "^5.2.0",
"@typescript-eslint/parser": "^5.2.0",
"builtin-modules": "^3.2.0",
"esbuild": "0.13.12",
"eslint": "^8.17.0",
"obsidian": "latest",
"obsidian-dataview": "^0.5.34",
"@typescript-eslint/eslint-plugin": "^5.29.0",
"@typescript-eslint/parser": "^5.29.0",
"builtin-modules": "^3.3.0",
"esbuild": "0.14.47",
"eslint": "^8.18.0",
"obsidian": "^0.15.2",
"obsidian-dataview": "^0.5.36",
"pg": "^8.7.3",
"pg-native": "^3.0.0",
"tslib": "2.3.1",
"typescript": "^4.7.3"
"tslib": "2.4.0",
"typescript": "^4.7.4"
}
}
27 changes: 21 additions & 6 deletions src/classes/postgresql-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { DataviewApi, getAPI } from "obsidian-dataview";
import { Client } from "pg";

export class PostgreSQLPlugin extends Plugin {
public settings: IPostgresPluginSettings;
// the settings are defined in `onload`. We can assert that they are defined
public settings!: IPostgresPluginSettings;
protected db: Client | undefined;

public async onload(): Promise<void> {
Expand All @@ -18,10 +19,15 @@ export class PostgreSQLPlugin extends Plugin {
id: "postgresql-upload-current-file",
name: "PostgreSQL: upload current file information",
callback: async () => {
const dv: DataviewApi = getAPI();
const dv: DataviewApi | undefined = getAPI();
if (!dv) {
// eslint-disable-next-line no-new
new Notice("The Dataview API is not available");
return;
}
const db: Client = await this.getDatabaseClient();

const filepath: string =
const filepath: string | undefined =
this.app.workspace.getActiveFile()?.path;

if (!filepath) {
Expand All @@ -30,7 +36,14 @@ export class PostgreSQLPlugin extends Plugin {
return;
}

const dataviewData: Record<string, unknown> = dv.page(filepath);
const dataviewData: Record<string, unknown> | undefined =
dv.page(filepath);

if (!dataviewData) {
// eslint-disable-next-line no-new
new Notice("Failed to fetch the dataview data");
return;
}

delete dataviewData.file;
delete dataviewData.position;
Expand All @@ -48,7 +61,7 @@ export class PostgreSQLPlugin extends Plugin {
);
} catch (err) {
// eslint-disable-next-line no-new
new Notice("PostgreSQL error: " + err.message);
new Notice("PostgreSQL error: " + (err as Error).message);
throw err;
}

Expand Down Expand Up @@ -83,7 +96,9 @@ export class PostgreSQLPlugin extends Plugin {
new Notice("Connected to PostgreSQL");
} catch (err) {
// eslint-disable-next-line no-new
new Notice("PostgreSQL connection error: " + err.message);
new Notice(
"PostgreSQL connection error: " + (err as Error).message
);
throw err;
}

Expand Down
4 changes: 3 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
"isolatedModules": true,
"skipLibCheck": true,
"noEmit": true,
"lib": ["DOM", "ES5", "ES6", "ES7"]
"lib": ["DOM", "ES5", "ES6", "ES7"],
"strict": true,
"strictNullChecks": true
},
"include": ["**/*.ts"]
}
Loading

0 comments on commit 7f1f7b0

Please sign in to comment.