Moving along. DB is being created now and starting to work on table.

This commit is contained in:
2023-03-07 21:09:32 -06:00
parent 338eb1efdf
commit affd073fea
10 changed files with 2162 additions and 52 deletions

View File

@ -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;
}

View File

@ -8,8 +8,6 @@
*/
// Attach all the needed helpers.
import "src/includes.ts";
import "includes.ts";
/* Main, UI */

View File

@ -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;
}
}

View File

@ -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();