Moving along. DB is being created now and starting to work on table.
This commit is contained in:
@ -6,17 +6,12 @@
|
||||
|
||||
import "objects.ts";
|
||||
|
||||
// Connect to a SQLite database.
|
||||
function connect_db () {
|
||||
|
||||
}
|
||||
|
||||
// Retrieve data from a connected database.
|
||||
function select_db () {
|
||||
|
||||
null;
|
||||
}
|
||||
|
||||
// Send data to a connected database.
|
||||
function post_db () {
|
||||
|
||||
null;
|
||||
}
|
||||
|
@ -8,8 +8,6 @@
|
||||
*/
|
||||
|
||||
// Attach all the needed helpers.
|
||||
import "src/includes.ts";
|
||||
import "includes.ts";
|
||||
|
||||
/* Main, UI */
|
||||
|
||||
|
||||
|
@ -7,7 +7,8 @@
|
||||
interface record {
|
||||
user_id: number;
|
||||
cal_date: string;
|
||||
meal: string; // Only wants options: Breakfast, Lunch, Dinner, Snack.
|
||||
food: string;
|
||||
caused_issue: boolean;
|
||||
comments: string;
|
||||
}
|
||||
}
|
||||
|
@ -5,11 +5,55 @@
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
/* DB Setup */
|
||||
/* Usage */
|
||||
|
||||
function usage (exit_code) {
|
||||
console.log(
|
||||
process.argv[1] + " is used to expose the SQLite backend to React.\n" +
|
||||
" It accepts the following parameters: \n" +
|
||||
" -h or --help: Display this usage text.\n" +
|
||||
" /path/to/project: Where the project lives and the db + scripts exist."
|
||||
);
|
||||
process.exit(exit_code);
|
||||
}
|
||||
|
||||
/* Test Code */
|
||||
// Just playing with the DB until learning React.
|
||||
/* Arguments */
|
||||
|
||||
let DIR = "";
|
||||
if (process.argv.length == 2 || process.argv.length >= 4 || process.argv[2] == undefined) {
|
||||
console.log('Expected one argument!');
|
||||
usage(1);
|
||||
} else if (process.argv[2] === "-h" || process.argv[2] === "--help") {
|
||||
usage(0);
|
||||
} else {
|
||||
DIR = process.argv[2];
|
||||
console.log("Successfully got DIR: ", DIR);
|
||||
}
|
||||
|
||||
/* Setup */
|
||||
|
||||
const sqlite3 = require('sqlite3').verbose();
|
||||
|
||||
async function finish () {
|
||||
await db.close();
|
||||
}
|
||||
|
||||
/* Main Program */
|
||||
|
||||
async function main() {
|
||||
console.log("Connecting to DB "+DIR+"/db/main");
|
||||
let db = await new sqlite3.Database(DIR+"/db/main");
|
||||
console.log(db);
|
||||
await db.run(`
|
||||
CREATE TABLE journal(
|
||||
user_id INTEGER NOT NULL,
|
||||
cal_date TEXT NOT NULL,
|
||||
meal TEXT NOT NULL,
|
||||
food TEXT NOT NULL,
|
||||
caused_issue INTEGER NOT NULL,
|
||||
comments TEXT
|
||||
) STRICT
|
||||
`);
|
||||
}
|
||||
|
||||
main();
|
||||
|
Reference in New Issue
Block a user