Ein Blog

TIL sqlite3_set_authorizer. Damit kann man einen Callback definieren, den SQLite aufruft, wenn eine Query auf eine bestimmte Datenbank/Tabelle/Spalte zugreifen möchte.

Gefunden, weil node:sqlite das jetzt kann:

import { DatabaseSync, constants } from 'node:sqlite';
const db = new DatabaseSync(':memory:');

// Set up an authorizer that denies all table creation
db.setAuthorizer((actionCode) => {
  if (actionCode === constants.SQLITE_CREATE_TABLE) {
    return constants.SQLITE_DENY;
  }
  return constants.SQLITE_OK;
});

// This will work
db.prepare('SELECT 1').get();

// This will throw an error due to authorization denial
try {
  db.exec('CREATE TABLE blocked (id INTEGER)');
} catch (err) {
  console.log('Operation blocked:', err.message);
}