Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/dbml-cli/src/cli/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ export default {
snowflake: {
name: 'Snowflake',
},
sqlite: {
name: 'SQLite'
}
};
1 change: 1 addition & 0 deletions packages/dbml-cli/src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function dbml2sql (args) {
.option('--postgres')
.option('--mssql')
.option('--oracle')
.option('--sqlite')
.option('-o, --out-file <pathspec>', 'compile all input files into a single files');
// .option('-d, --out-dir <pathspec>', 'compile an input directory of dbml files into an output directory');

Expand Down
2 changes: 1 addition & 1 deletion packages/dbml-cli/src/cli/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function validateInputFilePaths (paths, validatePlugin) {

function getFormatOpt (opts) {
const formatOpts = Object.keys(opts).filter((opt) => {
return ['postgres', 'mysql', 'mssql', 'postgresLegacy', 'mysqlLegacy', 'mssqlLegacy', 'oracle', 'snowflake'].includes(opt);
return ['postgres', 'mysql', 'mssql', 'postgresLegacy', 'mysqlLegacy', 'mssqlLegacy', 'oracle', 'snowflake', 'sqlite'].includes(opt);
});

let format = 'postgres';
Expand Down
5 changes: 5 additions & 0 deletions packages/dbml-core/__tests__/exporter/exporter.spec.js
Copy link
Contributor

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:

  • Fields that have types in the form of name(args) such as VARCHAR(255).
  • Various index types: unique, primary, functional, multi-column (unique and primary).
  • Unique constraints.
  • Default
  • Autoincrement.
  • Various referential actions.
  • Primary constraints.
  • Check constraints.
  • Enums
  • Multi-column, many-to-many, one-to-one, one-to-many, zero-to-one, zero-to-many Refs.
  • Not null constraints
  • Column types that have spaces in their names.
  • Table and column names that contain spaces in them
    You can look up the input for the test cases by reusing the other input files in the other exporters.

Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,10 @@ describe('@dbml/core - exporter', () => {
test.each(scanTestNames(__dirname, 'oracle_exporter/input'))('oracle_exporter/%s', (name) => {
runTest(name, 'oracle_exporter', 'oracle');
});

test.each(scanTestNames(__dirname, 'sqlite_exporter/input'))('sqlite_exporter/%s', (name) => {
runTest(name, 'sqlite_exporter', 'sqlite');
});

/* eslint-enable */
});
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]
}
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"
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"
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")
);
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");
Loading
Loading