Skip to content

Feature/database support#299

Open
IND-Subu wants to merge 5 commits into
DulLabs:developfrom
IND-Subu:feature/database-support
Open

Feature/database support#299
IND-Subu wants to merge 5 commits into
DulLabs:developfrom
IND-Subu:feature/database-support

Conversation

@IND-Subu
Copy link
Copy Markdown

🚀 Feature: SQLite Database Support for BhaiLang

This PR introduces first-class SQLite database support to BhaiLang using better-sqlite3, enabling BhaiLang programs to interact with real databases while maintaining BhaiLang’s fun syntax and simplicity.


✅ What This Adds

New Database Builtins

FunctionPurpose
database_connectOpens / creates a SQLite database file
database_executeRuns INSERT / UPDATE / DELETE / CREATE queries
database_queryFetches multiple rows
database_query_ekFetches a single row
database_closeCloses the database connection

Connections are tracked internally and reused per filename.


🧠 Design Philosophy

  • Keep BhaiLang simple
  • Avoid complex JS objects in runtime
  • Behave like statements, Bhai-style
  • Meaningful output
  • Safe argument validation

💻 Example Usage

hi bhai

  database_connect bhai "test.db";

  database_execute bhai "test.db" 
    "CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, naam TEXT, umar INTEGER)";

  database_execute bhai "test.db"
    "INSERT INTO users (naam, umar) VALUES ('Rahul', 25)";

  database_query bhai "test.db"
    "SELECT * FROM users";

  database_close bhai "test.db";

bye bhai

Sample Output

Attempting to connect to: test.db
Connected successfully: test.db
Query executed successfully
Found X rows bhai
[ { id: 1, naam: 'Rahul', umar: 25 } ]
Closed successfully

🔧 CLI Build Fix

better-sqlite3 is a native addon and cannot be bundled inside a single file. To ensure stability, the CLI build was updated to externalize:

  • better-sqlite3
  • bindings

This prevents runtime crashes like:

Cannot read properties of null (reading 'indexOf')

🛡️ Safety & Stability

  • Argument validation
  • Graceful runtime exceptions
  • Ensures DB is connected before execution
  • Safe cleanup
  • Automatic DB creation support

📌 Notes

  • Docs build remains unaffected
  • Works in Node CLI
  • Backwards compatible

🙏 Request

Kindly review and provide feedback. Happy to align syntax, naming, or behavior with BhaiLang’s philosophy.

Bhai ne DB ko bhi bhai bana diya 😎

@vercel
Copy link
Copy Markdown

vercel Bot commented Dec 30, 2025

@IND-Subu is attempting to deploy a commit to the Dullabs Team on Vercel.

A member of the Team first needs to authorize it.

@IND-Subu IND-Subu marked this pull request as draft February 21, 2026 17:23
@IND-Subu IND-Subu marked this pull request as ready for review February 21, 2026 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant