Skip to content

Commit 027e7d7

Browse files
Update SQLite adapter: configurable database path (#169)
1 parent de119c9 commit 027e7d7

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

lib/notification/adapter/sqlite.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
import { markdown2Html } from '../../services/markdown.js';
22
import Database from 'better-sqlite3';
3-
export const send = ({ serviceName, newListings, jobKey }) => {
4-
const db = new Database('db/listings.db');
3+
import path from 'path';
4+
import fs from 'fs';
5+
6+
export const send = ({ serviceName, newListings, jobKey, notificationConfig }) => {
7+
const sqliteConfig = notificationConfig.find((adapter) => adapter.id === config.id);
8+
const dbPath = sqliteConfig?.fields?.dbPath || 'db/listings.db';
9+
10+
const dbDir = path.dirname(dbPath);
11+
if (!fs.existsSync(dbDir)) {
12+
fs.mkdirSync(dbDir, { recursive: true });
13+
}
14+
15+
const db = new Database(dbPath);
516
const fields = [
617
'serviceName',
718
'jobKey',
@@ -30,8 +41,16 @@ export const send = ({ serviceName, newListings, jobKey }) => {
3041
};
3142
export const config = {
3243
id: 'sqlite',
33-
name: 'Sqlite',
34-
description: 'This adapter stores listings in a local sqlite3 database.',
35-
config: {},
44+
name: 'SQLite',
45+
description: 'This adapter stores listings in a local SQLite 3 database.',
46+
fields: {
47+
dbPath: {
48+
type: 'text',
49+
label: 'Database Path',
50+
description:
51+
'Path to the SQLite database file (e.g., db/listings.db). If not specified, defaults to db/listings.db',
52+
placeholder: 'db/listings.db',
53+
},
54+
},
3655
readme: markdown2Html('lib/notification/adapter/sqlite.md'),
3756
};

lib/notification/adapter/sqlite.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
### Sqlite Adapter
1+
### SQLite Adapter
22

3-
This adapter stores search results in a sqlite database located in db/listings.db. This file can be used for further analysis later on.
3+
This adapter stores search results in an SQLite database. By default, the database is located at `db/listings.db`, but you can configure a custom location. This file can be used for further analysis later.
44

5-
Fields are:
5+
The database table contains the following columns (all stored as `TEXT` type):
66

77
```
8-
['serviceName', 'jobKey', 'id', 'size', 'rooms', 'price', 'address', 'title', 'link', 'description']
8+
['serviceName', 'jobKey', 'id', 'size', 'rooms', 'price', 'address', 'title', 'link', 'description', 'image']
99
```

0 commit comments

Comments
 (0)