-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
11de56b
commit 60e0e10
Showing
4 changed files
with
124 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,4 +28,4 @@ dist-ssr | |
# Don't push the deploy keys to the public... | ||
.npmrc | ||
|
||
test_database.db | ||
test-database.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import sqlite3 from 'sqlite3' | ||
import path from 'path' | ||
import { fileURLToPath } from 'url' | ||
|
||
const __filename = fileURLToPath(import.meta.url) | ||
const __dirname = path.dirname(__filename) | ||
|
||
const dbPath = path.join(__dirname, './test-database.db') | ||
|
||
const db = new sqlite3.Database(dbPath, (err) => { | ||
if (err) { | ||
return | ||
} | ||
}) | ||
|
||
export { db } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,66 @@ | ||
import { db } from './db.js' | ||
|
||
function push(sessionId, path) { | ||
// Clear the redo stack! | ||
console.log('session id => ', sessionId) | ||
console.log('path => ', path) | ||
// Create a table in the db for each shell instance, so | ||
// that we can simply drop the table if a shell instance is | ||
// killed. | ||
// Clear the redo stack if present! | ||
|
||
db.serialize(() => { | ||
const tableName = `undo_stack_${sessionId}` | ||
// Create a table in the db for each shell instance, so | ||
// that we can simply drop the table if a shell instance is | ||
// killed. | ||
db.run( | ||
`CREATE TABLE IF NOT EXISTS ${tableName} ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
path TEXT NOT NULL | ||
)`, | ||
(err) => { | ||
if (err) { | ||
console.error('Error creating table:', err.message) | ||
} else { | ||
const stmt = db.prepare( | ||
`INSERT INTO ${tableName} (path) VALUES (?)` | ||
) | ||
stmt.run(path, (err) => { | ||
if (err) { | ||
console.error('Error inserting data:', err.message) | ||
} else { | ||
console.log('Data inserted successfully.') | ||
|
||
// Retrieve and print the contents of the table | ||
db.all( | ||
`SELECT * FROM ${tableName};`, | ||
(err, rows) => { | ||
if (err) { | ||
console.error( | ||
`Error retrieving data from ${tableName}:`, | ||
err.message | ||
) | ||
} else { | ||
console.log( | ||
`Contents of table ${tableName}:` | ||
) | ||
console.log(rows) | ||
} | ||
|
||
// Finalize the statement and close the database | ||
stmt.finalize(() => { | ||
db.close((err) => { | ||
if (err) { | ||
console.error( | ||
'Error closing the database:', | ||
err.message | ||
) | ||
} | ||
}) | ||
}) | ||
} | ||
) | ||
} | ||
}) | ||
} | ||
} | ||
) | ||
}) | ||
} | ||
|
||
export { push } |