Deno.js SQLite3 Database Tutorial to Perform CRUD Operations Using sqlite Module in TypeScript Full Project For Beginners

 

Deno SQLite Module

 

 

This is an SQLite module for JavaScript. The wrapper is targeted at Deno and uses a version of SQLite3 compiled to WebAssembly (WASM). This module focuses on ease of use and performance.

 

 

Documentation

 

 

Documentation is available as a website, on Deno Docs, or in the docs folder.

 

 

Example

 

 

import { DB } from "https://deno.land/x/sqlite/mod.ts";

// Open a database
const db = new DB("test.db");
db.query(
  "CREATE TABLE IF NOT EXISTS people (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)",
);

const names = ["Peter Parker", "Clark Kent", "Bruce Wayne"];

// Run a simple query
for (const name of names) {
  db.query("INSERT INTO people (name) VALUES (?)", [name]);
}

// Print out data in table
for (const [name] of db.query("SELECT name FROM people")) {
  console.log(name);
}

// Close connection
db.close();

 

 

Advantages

 

  • Security: benefit from Denos security settings, without the need to trust a third party
  • Portability: runs everywhere Deno runs and can even run in the browser
  • Easy: takes full advantage of Denos module cache and does not require any network access after initial download
See also  Node.js FFMPEG Command to Convert PDF to MP4 Video in Command Line Using Javascript Full Project For Beginners

 

Disadvantages

 

  • Speed: file system IO through Deno can be lower compared to what is achievable using a native code
  • Weaker Persistence Guarantees: due to limitations in Denos file system APIs, SQLite can’t acquire file locks or memory map files (e.g. this module can’t safely use WAL mode)

 

Leave a Reply