Menu

1 / 3

I put SQLite in a serverless function. Here's what it actually costs you.

DEV Community: serverless·Rudra Attri Pandey·8 days ago
#vk6eWkIC
#devtoserverless#devto#dev#database#file
Long article (1011 words) — no AI summary yet.
Reading 0:00
15s threshold

I run eleven small AI apps on a free Vercel plan. No managed Postgres, no Redis, no monthly bill. When you refuse to pay for a database, you end up asking a strange question: can SQLite just live inside the function?

The answer is yes. It also comes with a footgun that took me a while to see clearly, and I think most "SQLite on serverless" posts skip it.

The setup

The library is sql.js — SQLite compiled to WebAssembly. No native bindings, no build step, no binary that breaks on a different OS. It loads a .wasm file and gives you a database object in memory.

const initSqlJs = require ( 'sql.js' ) ;

const SQL = await initSqlJs ( { locateFile : ( ) => path . join ( __dirname , 'node_modules/sql.js/dist/sql-wasm.wasm' ) , } ) ;

const db = new SQL . Database ( ) ; db . run ( 'CREATE TABLE leads (id INTEGER PRIMARY KEY, email TEXT)' ) ;

Enter fullscreen mode

Exit fullscreen mode

From there it behaves like SQLite.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.