jsrosetta

Standard library

Databases (SQLite)

Node.js's node:sqlite compared to Go's go-sqlite3, Rust's rusqlite, Swift's SQLite3, and Java's sqlite-jdbc: creating a table, inserting, and querying.

Minimum versions
Node.js ≥ 22.13Go ≥ 1.21Rust ≥ 1.88Swift ≥ 3.0Java ≥ 25
Verified on
Node.js 24.12.0Go 1.27.1Rust 1.98.1Swift 6.2.4Java 25.0.4.1

Node.js code is an ES module: save it as .mjs or set "type": "module" in package.json.

The example below creates a table, inserts a few rows, and reads them back from SQLite. DROP TABLE IF EXISTS makes the example idempotent so it can be rerun. Node.js now has a built-in SQLite driver (node:sqlite); Go has no standard driver in its base library, so it needs an external package (database/sql plus the go-sqlite3 driver). Rust is the same story, using the rusqlite crate with the bundled feature (it compiles SQLite from source, so no system library is required). Swift calls the libsqlite3 C library that ships on Apple machines directly through the SQLite3 module. Java uses the external sqlite-jdbc driver through the standard java.sql API.

Creating a table, inserting, and querying

import { DatabaseSync } from 'node:sqlite'
 
const db = new DatabaseSync('./sqlite3.db')
 
db.exec('DROP TABLE IF EXISTS persons')
db.exec('CREATE TABLE persons (name TEXT)')
 
const insert = db.prepare('INSERT INTO persons VALUES (?)')
const names = ['alice', 'bob', 'charlie']
for (const name of names) {
  insert.run(name)
}
 
const select = db.prepare('SELECT rowid AS id, name FROM persons')
for (const row of select.all()) {
  console.log(row.id, row.name) // 1 alice / 2 bob / 3 charlie
}
 
db.close()

Reference: github.com/miguelmota/golang-for-nodejs-developers#databases