This repo provides a method to generate Dart Schema from MongoDb
- Install pnpm
- Run
pnpm i
to install dependencies - Run
cp .env.template .env
to create a .env file - Populate
.env
file with your MongoDBURL
andDB_NAME
- Copy your sync rules to
sync-rules.yaml
- Run
pnpm generateSchema
You should see output similar to the following:
Schema([
Table('products', [
Column.text('_id'),
Column.text('name'),
Column.text('category'),
Column.real('price'),
Column.integer('inStock'),
Column.text('features'),
Column.text('dimensions'),
Column.text('releaseDate'),
Column.text('ratings')
]),
...
]);
- This has only been minimally tested and therefore the output should be reviewed to confirm correctness.
- This only works for Dart Schema at present.
- None of the code has been optimized for performance.
NumberDecimals
are converted totext
and need to be manually adjusted toreal
.
This assumes you have Docker installed and running:
- Run
pnpm i
cp .env.template .env
- Run
./setup_mongodb.sh
- Run
pnpm generateSchema
You should see the following output:
Schema([
Table('products', [
Column.text('_id'),
Column.text('name'),
Column.text('category'),
Column.real('price'),
Column.integer('inStock'),
Column.text('features'),
Column.text('dimensions'),
Column.text('releaseDate'),
Column.text('ratings')
]),
Table('users', [
Column.text('_id'),
Column.text('username'),
Column.text('email'),
Column.integer('age'),
Column.integer('isActive'),
Column.text('registrationDate'),
Column.text('lastLogin'),
Column.text('preferences'),
Column.text('tags'),
Column.text('scores')
]),
Table('orders', [
Column.text('_id'),
Column.text('userId'),
Column.text('orderDate'),
Column.text('status'),
Column.text('totalAmount'),
Column.text('items'),
Column.text('shippingAddress'),
Column.text('paymentMethod'),
Column.text('paypalTransactionId'),
Column.text('bankTransactionId'),
Column.text('lastFourDigits')
])
]);
- Collections are used to generate table names.
- Collection documents are sampled to generate the table columns. Number of documents sampled is based on SAMPLE_SIZE_INT set in
.env
file. - Sync rules are used to filter out tables generated from collections that are not required.