Added better-sqlite3 dep and created default db

Signed-off-by: Martin Berg Alstad <git@martials.no>
This commit is contained in:
Martin Berg Alstad 2024-12-26 12:49:54 +01:00 committed by Martin Berg Alstad
parent 6650e2cd2b
commit 8854a22b40
Signed by: martials
GPG Key ID: C4EA170D0B21376A
4 changed files with 30 additions and 1 deletions

0
default.sqlite Normal file
View File

View File

@ -4,7 +4,7 @@
"description": "",
"main": "index.js",
"scripts": {
"start": "node --import=tsx ./src/main.ts | pino-pretty",
"start": "dotenvx run --env-file=.env.local -- node --import=tsx ./src/main.ts | pino-pretty",
"test": "dotenvx run --env-file=.env.test.local -- node --experimental-vm-modules node_modules/jest/bin/jest.js | pino-pretty",
"format": "prettier --write \"./**/*.{js,mjs,ts,md,json}\""
},
@ -14,6 +14,7 @@
"dependencies": {
"@actual-app/api": "^24.12.0",
"@dotenvx/dotenvx": "^1.31.3",
"better-sqlite3": "^11.7.0",
"cron": "^3.3.1",
"dayjs": "^1.11.13",
"dotenv": "^16.4.7",
@ -22,6 +23,7 @@
},
"devDependencies": {
"@jest/globals": "^29.7.0",
"@types/better-sqlite3": "^7.6.12",
"@types/jest": "^29.5.14",
"@types/node": "^22.10.2",
"jest": "^29.7.0",

20
pnpm-lock.yaml generated
View File

@ -11,6 +11,9 @@ dependencies:
'@dotenvx/dotenvx':
specifier: ^1.31.3
version: 1.31.3
better-sqlite3:
specifier: ^11.7.0
version: 11.7.0
cron:
specifier: ^3.3.1
version: 3.3.1
@ -31,6 +34,9 @@ devDependencies:
'@jest/globals':
specifier: ^29.7.0
version: 29.7.0
'@types/better-sqlite3':
specifier: ^7.6.12
version: 7.6.12
'@types/jest':
specifier: ^29.5.14
version: 29.5.14
@ -993,6 +999,12 @@ packages:
'@babel/types': 7.26.3
dev: true
/@types/better-sqlite3@7.6.12:
resolution: {integrity: sha512-fnQmj8lELIj7BSrZQAdBMHEHX8OZLYIHXqAKT1O7tDfLxaINzf00PMjw22r3N/xXh0w/sGHlO6SVaCQ2mj78lg==}
dependencies:
'@types/node': 22.10.2
dev: true
/@types/graceful-fs@4.1.9:
resolution: {integrity: sha512-olP3sd1qOEe5dXTSaFvQG+02VdRXcdytWLAZsAq1PecU8uqQAhkrnbli7DagjtXKW/Bl7YJbUsa8MPcuc8LHEQ==}
dependencies:
@ -1193,6 +1205,14 @@ packages:
resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==}
dev: false
/better-sqlite3@11.7.0:
resolution: {integrity: sha512-mXpa5jnIKKHeoGzBrUJrc65cXFKcILGZpU3FXR0pradUEm9MA7UZz02qfEejaMcm9iXrSOCenwwYMJ/tZ1y5Ig==}
requiresBuild: true
dependencies:
bindings: 1.5.0
prebuild-install: 7.1.2
dev: false
/better-sqlite3@9.6.0:
resolution: {integrity: sha512-yR5HATnqeYNVnkaUTf4bOP2dJSnyhP4puJN/QPRyx4YkBEEUxib422n2XzPqDEHjQQqazoYoADdAm5vE15+dAQ==}
requiresBuild: true

View File

@ -9,9 +9,11 @@ import { bankTransactionIntoActualTransaction } from "@/mappings.ts"
import { ACTUAL_ACCOUNT_IDS, BANK_ACCOUNT_IDS } from "../config.ts"
import logger from "@/logger.ts"
import type { UUID } from "node:crypto"
import Database from "better-sqlite3"
// TODO Transports api for pino https://github.com/pinojs/pino/blob/HEAD/docs/transports.md
// TODO create .cache if missing
// TODO store oauth tokens in a SQLite db, use same dep as actual
export async function daily(actual: Actual, bank: Bank): Promise<void> {
// Fetch transactions from the bank
@ -48,6 +50,10 @@ async function fetchTransactionsFromPastDay(
async function main(): Promise<void> {
logger.info("Starting application")
const actual = await ActualImpl.init()
const databaseFileName = "default.sqlite"
const db = new Database(databaseFileName)
logger.info(`Started SQLlite database with filename="${databaseFileName}"`)
logger.info("Waiting for CRON job to start")
cronJobDaily(async () => {
@ -58,6 +64,7 @@ async function main(): Promise<void> {
// logger.info("Shutting down")
// await actual.shutdown()
// db.close()
}
void main()