https://github.com/zdunecki/bson2sql
convert bson file to sql script
https://github.com/zdunecki/bson2sql
Last synced: 5 days ago
JSON representation
convert bson file to sql script
- Host: GitHub
- URL: https://github.com/zdunecki/bson2sql
- Owner: zdunecki
- Created: 2025-11-13T22:34:18.000Z (7 months ago)
- Default Branch: master
- Last Pushed: 2025-11-13T22:52:44.000Z (7 months ago)
- Last Synced: 2025-11-14T00:26:30.168Z (7 months ago)
- Language: JavaScript
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# BSON to SQL Converter
Convert MongoDB BSON exports to SQL import scripts using a schema definition.
## Features
- Parses BSON files and generates SQL scripts for PostgreSQL, MySQL, or SQLite
- Supports custom schema mapping and type conversion
- Handles array fields and nested objects
- CLI usage for easy integration
## Installation
```bash
bun install
```
## Usage
```bash
bun run build
node ./dist/index.js [database_type]
```
- ``: Path to the BSON file exported from MongoDB
- ``: Path to the schema definition JSON file
- `[database_type]`: Optional, one of `mysql`, `postgresql`, or `sqlite` (default: `mysql`)
or via `bunx`:
```bash
bunx bson2sql [database_type]
```
### Example
```bash
node ./dist/index.js data.bson schema.json mysql
```
## Example Schema
```json
{
"tables": {
"users": {
"primary_key": "id",
"columns": {
"id": "id",
"username": "string",
"email": "string",
"created_at": "datetime",
"is_active": "boolean",
"profile_data": "json"
},
"not_null": ["username", "email"],
"field_mapping": {
"id": "_id",
"username": "username",
"email": "email",
"created_at": "createdAt",
"is_active": "active",
"profile_data": "profile"
}
}
}
}
```
## License
MIT
# bson2sql