Created
April 29, 2021 14:31
-
-
Save erming/cb0db8cba0d41275bc92438dc1c16c41 to your computer and use it in GitHub Desktop.
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
const fastify = require("fastify"); | |
const sqlite3 = require("sqlite3"); | |
const { nanoid } = require("nanoid"); | |
const app = fastify(); | |
const db = new sqlite3.Database(":memory:"); | |
db.serialize(); | |
db.run(` | |
CREATE TABLE data ( | |
id INTEGER PRIMARY KEY AUTOINCREMENT, | |
value TEXT NOT NULL | |
); | |
`); | |
for (let i = 0; i < 1000; i++) { | |
db.run(`INSERT INTO data (value) VALUES (?)`, nanoid()); | |
} | |
db.parallelize(); | |
app.get("/", (req, res) => { | |
db.all("SELECT * FROM data", (_, rows) => { | |
res.send(rows); | |
}); | |
}); | |
app.listen(9999); | |
console.log(""); | |
console.log("Running on http://127.0.0.1:9999/"); | |
console.log("Ctrl-c to stop"); | |
console.log(""); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment