-
Notifications
You must be signed in to change notification settings - Fork 213
feat(dbml/core): adds support for exporting to sqlite #752
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
danielgary
wants to merge
3
commits into
holistics:master
Choose a base branch
from
danielgary:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,4 +20,7 @@ export default { | |
| snowflake: { | ||
| name: 'Snowflake', | ||
| }, | ||
| sqlite: { | ||
| name: 'SQLite' | ||
| } | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
packages/dbml-core/__tests__/exporter/sqlite_exporter/input/1_to_1_relations.in.dbml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| Table father { | ||
| obj_id char(50) [primary key, unique] | ||
| } | ||
|
|
||
| Table child { | ||
| obj_id char(50) [primary key, unique] | ||
| father_obj_id char(50) [ref: - father.obj_id] | ||
| } |
81 changes: 81 additions & 0 deletions
81
packages/dbml-core/__tests__/exporter/sqlite_exporter/input/general_schema.in.dbml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| Enum "orders_status_enum" { | ||
| "created" | ||
| "running" | ||
| "done" | ||
| "failure" | ||
| } | ||
|
|
||
| Enum "products_status_enum" { | ||
| "Out of Stock" | ||
| "In Stock" | ||
| } | ||
|
|
||
| Table "orders" { | ||
| "id" int [pk, increment] | ||
| "user_id" int [unique, not null] | ||
| "status" orders_status_enum | ||
| "created_at" varchar(255) [note: 'When order created'] | ||
|
|
||
| Note: 'This is a note in table "orders"' | ||
| } | ||
|
|
||
| Table "order_items" { | ||
| "order_id" int | ||
| "product_id" int | ||
| "quantity" int [default: 1] | ||
| } | ||
|
|
||
| Table "products" { | ||
| "id" int | ||
| "name" varchar(255) | ||
| "merchant_id" int [not null] | ||
| "price" int | ||
| "status" products_status_enum | ||
| "created_at" datetime [default: `CURRENT_TIMESTAMP`] | ||
|
|
||
| Indexes { | ||
| (id, name) [pk] | ||
| (merchant_id, status) [name: "product_status"] | ||
| id [type: hash, unique, name: "products_index_1"] | ||
| } | ||
|
|
||
| Note: "This is a note in table 'products'" | ||
| } | ||
|
|
||
| Table "users" { | ||
| "id" int [pk] | ||
| "full_name" varchar(255) | ||
| "email" varchar(255) [unique] | ||
| "gender" varchar(255) | ||
| "date_of_birth" varchar(255) | ||
| "created_at" varchar(255) | ||
| "country_code" int | ||
|
|
||
| Note: 'This is a note in table "users"' | ||
| } | ||
|
|
||
| Table "merchants" { | ||
| "id" int [pk] | ||
| "merchant_name" varchar(255) | ||
| "country_code" int | ||
| "created_at" varchar(255) | ||
| "admin_id" int | ||
| } | ||
|
|
||
| Table "countries" { | ||
| "code" int [pk] | ||
| "name" varchar(255) | ||
| "continent_name" varchar(255) | ||
| } | ||
|
|
||
| Ref:"orders"."id" < "order_items"."order_id" | ||
|
|
||
| Ref:"products"."id" < "order_items"."product_id" | ||
|
|
||
| Ref:"countries"."code" < "users"."country_code" | ||
|
|
||
| Ref:"countries"."code" < "merchants"."country_code" | ||
|
|
||
| Ref:"merchants"."id" < "products"."merchant_id" | ||
|
|
||
| Ref:"users"."id" < "merchants"."admin_id" |
86 changes: 86 additions & 0 deletions
86
...ages/dbml-core/__tests__/exporter/sqlite_exporter/input/many_to_many_relationship.in.dbml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| table "A"."a" { | ||
| "AB" integer [pk] | ||
| "BA" integer [pk] | ||
| } | ||
|
|
||
| table "B"."b" { | ||
| "BC" integer [pk] | ||
| "CB" integer [pk] | ||
| } | ||
|
|
||
| table "C"."c" { | ||
| "CD" integer [pk, ref: <> "D"."d"."DE"] | ||
| "DC" integer | ||
| } | ||
|
|
||
| table "D"."d" { | ||
| "DE" integer [pk] | ||
| "ED" integer | ||
| } | ||
|
|
||
| table "E"."e" { | ||
| "EF" integer [pk] | ||
| "FE" integer [pk] | ||
| "DE" integer | ||
| "ED" integer | ||
| } | ||
|
|
||
| table "G"."g" { | ||
| "GH" integer [pk] | ||
| "HG" integer [pk] | ||
| "EH" integer | ||
| "HE" integer | ||
| } | ||
|
|
||
| ref: "A"."a".("AB","BA") <> "B"."b".("BC","CB") | ||
| ref: "E"."e".("EF","FE") <> "G"."g".("GH","HG") | ||
|
|
||
|
|
||
| table t1 { | ||
| a int [pk] | ||
| b int [unique] | ||
| } | ||
|
|
||
| table t2 { | ||
| a int [pk] | ||
| b int [unique] | ||
| } | ||
|
|
||
| table t1_t2 { | ||
| a int | ||
| } | ||
|
|
||
| ref: t1.a <> t2.a | ||
| ref: t1.b <> t2.b | ||
|
|
||
| Table schema.image { | ||
| id integer [pk] | ||
| url varchar | ||
| } | ||
|
|
||
| Table schema.content_item { | ||
| id integer [pk] | ||
| heading varchar | ||
| description varchar | ||
| } | ||
|
|
||
| Ref: schema.image.id <> schema.content_item.id | ||
|
|
||
| Table schema.footer_item { | ||
| id integer [pk] | ||
| left varchar | ||
| centre varchar | ||
| right varchar | ||
| } | ||
|
|
||
| Table "schema1"."customers" { | ||
| "id" integer [pk] | ||
| "full_name" varchar | ||
| } | ||
|
|
||
| Table "schema2"."orders" { | ||
| "id" integer [pk] | ||
| "total_price" integer | ||
| } | ||
|
|
||
| Ref: "schema1"."customers"."id" <> "schema2"."orders"."id" |
11 changes: 11 additions & 0 deletions
11
packages/dbml-core/__tests__/exporter/sqlite_exporter/output/1_to_1_relations.out.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| PRAGMA foreign_keys = ON; | ||
|
|
||
| CREATE TABLE "father" ( | ||
| "obj_id" TEXT UNIQUE PRIMARY KEY | ||
| ); | ||
|
|
||
| CREATE TABLE "child" ( | ||
| "obj_id" TEXT UNIQUE PRIMARY KEY, | ||
| "father_obj_id" TEXT, | ||
| FOREIGN KEY ("father_obj_id") REFERENCES "father" ("obj_id") | ||
| ); |
58 changes: 58 additions & 0 deletions
58
packages/dbml-core/__tests__/exporter/sqlite_exporter/output/general_schema.out.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| PRAGMA foreign_keys = ON; | ||
|
|
||
| CREATE TABLE "orders" ( | ||
| "id" INTEGER PRIMARY KEY AUTOINCREMENT, | ||
| "user_id" INTEGER UNIQUE NOT NULL, | ||
| "status" TEXT CHECK ("status" IN ('created','running','done','failure')), | ||
| "created_at" TEXT | ||
| ); | ||
|
|
||
| CREATE TABLE "countries" ( | ||
| "code" INTEGER PRIMARY KEY, | ||
| "name" TEXT, | ||
| "continent_name" TEXT | ||
| ); | ||
|
|
||
| CREATE TABLE "users" ( | ||
| "id" INTEGER PRIMARY KEY, | ||
| "full_name" TEXT, | ||
| "email" TEXT UNIQUE, | ||
| "gender" TEXT, | ||
| "date_of_birth" TEXT, | ||
| "created_at" TEXT, | ||
| "country_code" INTEGER, | ||
| FOREIGN KEY ("country_code") REFERENCES "countries" ("code") | ||
| ); | ||
|
|
||
| CREATE TABLE "merchants" ( | ||
| "id" INTEGER PRIMARY KEY, | ||
| "merchant_name" TEXT, | ||
| "country_code" INTEGER, | ||
| "created_at" TEXT, | ||
| "admin_id" INTEGER, | ||
| FOREIGN KEY ("country_code") REFERENCES "countries" ("code"), | ||
| FOREIGN KEY ("admin_id") REFERENCES "users" ("id") | ||
| ); | ||
|
|
||
| CREATE TABLE "products" ( | ||
| "id" INTEGER, | ||
| "name" TEXT, | ||
| "merchant_id" INTEGER NOT NULL, | ||
| "price" INTEGER, | ||
| "status" TEXT CHECK ("status" IN ('Out of Stock','In Stock')), | ||
| "created_at" TEXT DEFAULT (CURRENT_TIMESTAMP), | ||
| PRIMARY KEY ("id","name"), | ||
| FOREIGN KEY ("merchant_id") REFERENCES "merchants" ("id") | ||
| ); | ||
|
|
||
| CREATE TABLE "order_items" ( | ||
| "order_id" INTEGER, | ||
| "product_id" INTEGER, | ||
| "quantity" INTEGER DEFAULT 1, | ||
| FOREIGN KEY ("order_id") REFERENCES "orders" ("id"), | ||
| FOREIGN KEY ("product_id") REFERENCES "products" ("id") | ||
| ); | ||
|
|
||
| CREATE INDEX "product_status" ON "products" ("merchant_id","status"); | ||
|
|
||
| CREATE UNIQUE INDEX "products_index_1" ON "products" ("id"); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The testcases are failing. Please help update the tests!
Also, can you verify that the following cases are covered in the test cases:
name(args)such asVARCHAR(255).You can look up the input for the test cases by reusing the other input files in the other exporters.