feat: Introduce financial goal and asset management with SQLite and NativeWind integration, new tab screens, and updated dependencies.
This commit is contained in:
54
db/index.ts
Normal file
54
db/index.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { openDatabaseSync } from 'expo-sqlite';
|
||||
import { Platform } from 'react-native';
|
||||
|
||||
let db: any;
|
||||
if (Platform.OS !== 'web') {
|
||||
db = openDatabaseSync('finance.db');
|
||||
} else {
|
||||
// Mock DB for web to prevent crash
|
||||
db = {
|
||||
execSync: () => { },
|
||||
getAllAsync: async () => [],
|
||||
runAsync: async () => { },
|
||||
getFirstAsync: async () => null,
|
||||
};
|
||||
}
|
||||
|
||||
export const initDatabase = () => {
|
||||
try {
|
||||
db.execSync(`
|
||||
CREATE TABLE IF NOT EXISTS transactions (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
amount REAL NOT NULL,
|
||||
category TEXT NOT NULL,
|
||||
date TEXT NOT NULL,
|
||||
description TEXT,
|
||||
type TEXT NOT NULL -- 'income' or 'expense'
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS assets (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL,
|
||||
type TEXT NOT NULL, -- 'stock', 'crypto', 'real_estate', etc.
|
||||
value REAL NOT NULL,
|
||||
quantity REAL,
|
||||
purchase_date TEXT
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS goals (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL,
|
||||
target_amount REAL NOT NULL,
|
||||
current_amount REAL NOT NULL DEFAULT 0,
|
||||
deadline TEXT
|
||||
);
|
||||
`);
|
||||
console.log('Database initialized successfully');
|
||||
return Promise.resolve(true);
|
||||
} catch (error) {
|
||||
console.error('Error initializing database', error);
|
||||
return Promise.reject(error);
|
||||
}
|
||||
};
|
||||
|
||||
export const getDB = () => db;
|
||||
Reference in New Issue
Block a user