Skip to content

Commit

Permalink
Fixed sqlite (#95)
Browse files Browse the repository at this point in the history
* started the SQLite class. Still have to fix types.

* fixed the issues with the sqlite class.

Co-authored-by: Ideen <[email protected]>

* mobile view fixed (#94)

* Amplify working code

* Final Backend Deployment cahnges

* Bump next from 14.1.0 to 14.1.1 (#88)

Bumps [next](https://github.com/vercel/next.js) from 14.1.0 to 14.1.1.
- [Release notes](https://github.com/vercel/next.js/releases)
- [Changelog](https://github.com/vercel/next.js/blob/canary/release.js)
- [Commits](vercel/next.js@v14.1.0...v14.1.1)

---
updated-dependencies:
- dependency-name: next
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Tel 107 add unit conversion to pis transformer (#86)

* started unit conversion logic

* Create dockerfile for backend (#77)

* make the CarGraphicComponent SSR instead of the HeroComponent (#80)

* local storage and darkmode settings implemented

* Create dockerfile for backend (#77)

* make the CarGraphicComponent SSR instead of the HeroComponent (#80)

* local storage and darkmode settings implemented

* continued unit conversion function

Co-authored-by: JenniferJa <[email protected]>

* finsihed unit handler function without changes from setting modal changes

* yarn issue fixed by brian

* local storage and darkmode settings implemented

* yarn issue fixed by brian

* moved enum to appStateContext

* fixed small issue with displaying units

* fixed PR comments

* made unit conversion logic work with setting modal

* made speed adapt value adapt to change in units

* addressed comments. Changed to switch, case and destructured appState

* changed to switch

* fixed bug with undefined units and addressed comment

* fixed the miles per hour to 0 decimal places

---------

Co-authored-by: alexwhelan12 <[email protected]>
Co-authored-by: brian nguyen <[email protected]>
Co-authored-by: jenniferja <[email protected]>
Co-authored-by: JenniferJa <[email protected]>

* mobile view fixed

* some changes

* Should be good

* change to scrollbars

* scrollbar spacing

* oops

* please im begging

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: ideen1 <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Ideen <[email protected]>
Co-authored-by: alexwhelan12 <[email protected]>
Co-authored-by: brian nguyen <[email protected]>
Co-authored-by: jenniferja <[email protected]>
Co-authored-by: JenniferJa <[email protected]>

* removed database.sqlite file

* Fixed package

* Add SQLITE back

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Ideen <[email protected]>
Co-authored-by: Burton Jong <[email protected]>
Co-authored-by: ideen1 <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Ideen <[email protected]>
Co-authored-by: brian nguyen <[email protected]>
Co-authored-by: jenniferja <[email protected]>
Co-authored-by: JenniferJa <[email protected]>
  • Loading branch information
9 people authored Jun 4, 2024
1 parent a49effb commit 5be38eb
Show file tree
Hide file tree
Showing 9 changed files with 727 additions and 1,139 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ server/dist
# misc
.DS_Store
*.pem
.sqlite

# debug
npm-debug.log*
Expand Down
1,717 changes: 582 additions & 1,135 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@react-three/drei": "^9.99.3",
"@react-three/fiber": "^8.15.16",
"@react-three/postprocessing": "^2.16.0",
"@types/sqlite3": "^3.1.11",
"@types/three": "^0.161.2",
"aws-amplify": "^6.0.17",
"axios": "^1.6.7",
Expand All @@ -52,6 +53,7 @@
"rimraf": "^5.0.5",
"socket.io": "^4.7.5",
"socket.io-client": "^4.7.5",
"sqlite": "^5.1.1",
"three": "^0.161.0",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
Expand Down
2 changes: 1 addition & 1 deletion server/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
node: true,
es2021: true,
},
extends: ["eslint:recommended"],
// extends: ["eslint:recommended"],
rules: {
"no-unused-vars": ["warn", { argsIgnorePattern: "_" }],
},
Expand Down
5 changes: 5 additions & 0 deletions server/nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"watch": ["src"],
"ext": "ts",
"exec": "ts-node ./src/server.ts"
}
34 changes: 34 additions & 0 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions server/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
{
"main": "dist/server.js",
"license": "ISC",
"scripts": {
"clean": "rimraf dist",
"start": "node -r ts-node/register -r tsconfig-paths/register .",
"build": "npm-run-all clean tsc",
"dev:start": "npm-run-all build start",
"dev": "nodemon --watch src -e ts,ejs --exec \"npm run dev:start\"",
"dev": "nodemon - exec 'ts-node' src/server.ts",
"tsc": "tsc -p ./tsconfig.json"
},
"dependencies": {
"@types/sqlite3": "^3.1.11"
}
}
97 changes: 97 additions & 0 deletions server/src/controllers/SQLite.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import sqlite3 from "sqlite3";

import type ITelemetryData from "@/client/objects/telemetry-data.interface";

class SQLite {
private db: sqlite3.Database;
constructor(dbPath: string) {
this.db = new sqlite3.Database(dbPath, (err: Error | null) => {
if (err) {
console.error("Error opening database:", err.message);
} else {
console.log("Connected to the SQLite database.");
}
});

this.db
.prepare(
"CREATE TABLE IF NOT EXISTS packetData (id INTEGER PRIMARY KEY, date TEXT, data TEXT)",
)
.run()
.finalize();
this.db
.prepare(
"CREATE TABLE IF NOT EXISTS lapData (id INTEGER PRIMARY KEY, date TEXT, data TEXT)",
)
.run()
.finalize();
}

//Helper function to run a query
private runQuery(sql: string, params: any[]): Promise<{ id: number }> {
return new Promise((resolve, reject) => {
this.db.run(
sql,
params,
function (this: sqlite3.RunResult, err: Error | null) {
if (err) {
reject(new Error(`Error running SQL: ${err.message}`));
} else {
resolve({ id: this.lastID });
}
},
);
});
}

//Helper function to get all rows
private getAllRows(sql: string): Promise<ITelemetryData[]> {
return new Promise<ITelemetryData[]>((resolve, reject) => {
this.db.all(sql, (err: Error | null, rows: any[]) => {
if (err) {
reject(new Error(`Error retrieving data: ${err.message}`));
} else {
// Deserialize JSON strings to ITelemetryData objects
const telemetryData = rows.map((row) => JSON.parse(row.data));
resolve(telemetryData);
}
});
});
}

//Four basic insert and select functions
public insertPacketData(packet: ITelemetryData): Promise<{ id: number }> {
const sql = "INSERT INTO packetData (date, data) VALUES (?, ?)";
const data = JSON.stringify(packet); // Serialize ITelemetryData to JSON
return this.runQuery(sql, [packet.TimeStamp, data]);
}
public insertLapData(packet: ITelemetryData): Promise<{ id: number }> {
const sql = "INSERT INTO lapData (date, data) VALUES (?, ?)";
const data = JSON.stringify(packet); // Serialize ITelemetryData to JSON
return this.runQuery(sql, [packet.TimeStamp, data]);
}

public getPacketData(): Promise<ITelemetryData[]> {
const sql = "SELECT * FROM packetData";
return this.getAllRows(sql);
}
public getLapData(): Promise<ITelemetryData[]> {
const sql = "SELECT * FROM lapData";
return this.getAllRows(sql);
}

//Close the connection to the database
public close(): Promise<void> {
return new Promise((resolve, reject) => {
this.db.close((err) => {
if (err) {
reject(new Error(`Error closing the database: ${err.message}`));
} else {
resolve();
}
});
});
}
}

export default SQLite;
2 changes: 1 addition & 1 deletion server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import server from "@/index";
import { createLightweightApplicationLogger } from "@/utils/logger";

const logger = createLightweightApplicationLogger("server.ts");
const port = process.env.SERVER_PORT;
const port = process.env.SERVER_PORT || 3001;

export const httpServer = server
.listen(port, () => {
Expand Down

0 comments on commit 5be38eb

Please sign in to comment.