Skip to content

Instantly share code, notes, and snippets.

@erming
Created April 29, 2021 14:31
Show Gist options
  • Save erming/cb0db8cba0d41275bc92438dc1c16c41 to your computer and use it in GitHub Desktop.
Save erming/cb0db8cba0d41275bc92438dc1c16c41 to your computer and use it in GitHub Desktop.
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