Skip to content
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

fix: type of note field that is string doesn show #487

Merged
merged 3 commits into from
Jan 18, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@
}
},
"inline_refs": [],
"note": {
"value": "Status of an order"
}
"note": "Status of an order"
},
{
"name": "created_at",
Expand Down Expand Up @@ -106,6 +104,7 @@
"column": 2
}
},
"note": "User orders",
"indexes": []
}
],
Expand Down Expand Up @@ -155,9 +154,7 @@
"column": 1
}
},
"note": {
"value": "In stock"
}
"note": "In stock"
},
{
"name": "running_low",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ Table "orders" {
"user_id" int [unique, not null]
"status" varchar [note: 'Status of an order']
"created_at" varchar [note: 'When order created']
Note: 'User orders'
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@
}
},
"inline_refs": [],
"note": {
"value": "Status of an order"
}
"note": "Status of an order"
},
{
"name": "created_at",
Expand Down Expand Up @@ -106,6 +104,7 @@
"column": 2
}
},
"note": "User orders",
"indexes": []
}
],
Expand Down Expand Up @@ -155,9 +154,7 @@
"column": 1
}
},
"note": {
"value": "In stock"
}
"note": "In stock"
},
{
"name": "running_low",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ CREATE TABLE `orders` (
`status` varchar(255) COMMENT 'Status of an order',
`created_at` varchar(255) COMMENT 'When order created'
);

ALTER TABLE `orders` COMMENT = 'User orders';
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
"column": 2
}
},
"note": "User orders",
"indexes": []
}
],
Expand Down Expand Up @@ -155,9 +156,7 @@
"column": 1
}
},
"note": {
"value": "In stock"
}
"note": "In stock"
},
{
"name": "running_low",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ CREATE TABLE "orders" (
"created_at" varchar
);

COMMENT ON TABLE "orders" IS 'User orders';

COMMENT ON COLUMN "orders"."status" IS 'Status of an order';

COMMENT ON COLUMN "orders"."created_at" IS 'When order created';
6 changes: 3 additions & 3 deletions packages/dbml-core/src/model_structure/database.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _ from 'lodash';
import _, { get } from 'lodash';
import Schema from './schema';
import Ref from './ref';
import Enum from './enum';
Expand All @@ -25,8 +25,8 @@ class Database extends Element {
this.generateId();
this.hasDefaultSchema = false;
this.schemas = [];
this.note = project.note ? project.note.value : null;
this.noteToken = project.note ? project.note.token : null;
this.note = project.note ? get(project, 'note.value', project.note) : null;
this.noteToken = project.note ? get(project, 'note.token', project.noteToken) : null;
this.databaseType = project.database_type;
this.name = project.name;
this.aliases = aliases;
Expand Down
7 changes: 4 additions & 3 deletions packages/dbml-core/src/model_structure/enum.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { get } from 'lodash';
import Element from './element';
import EnumValue from './enumValue';
import { shouldPrintSchema } from './utils';

class Enum extends Element {
constructor ({
name, token, values, note, schema,
name, token, values, note, schema, noteToken = null,
} = {}) {
super(token);
if (!name) { this.error('Enum must have a name'); }
this.name = name;
this.note = note ? note.value : null;
this.noteToken = note ? note.token : null;
this.note = note ? get(note, 'value', note) : null;
this.noteToken = note ? get(note, 'token', noteToken) : null;
this.values = [];
this.fields = [];
this.schema = schema;
Expand Down
7 changes: 4 additions & 3 deletions packages/dbml-core/src/model_structure/enumValue.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { get } from 'lodash';
import Element from './element';

class EnumValue extends Element {
constructor ({
name, token, note, _enum,
name, token, note, _enum, noteToken = null,
} = {}) {
super(token);
if (!name) { this.error('Enum value must have a name'); }
this.name = name;
this.note = note ? note.value : null;
this.noteToken = note ? note.token : null;
this.note = note ? get(note, 'value', note) : null;
this.noteToken = note ? get(note, 'token', noteToken) : null;
this._enum = _enum;
this.dbState = this._enum.dbState;
this.generateId();
Expand Down
7 changes: 4 additions & 3 deletions packages/dbml-core/src/model_structure/field.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { get } from 'lodash';
import Element from './element';
import { DEFAULT_SCHEMA_NAME } from './config';

class Field extends Element {
constructor ({
name, type, unique, pk, token, not_null: notNull, note, dbdefault,
increment, table = {},
increment, table = {}, noteToken = null,
} = {}) {
super(token);
if (!name) { this.error('Field must have a name'); }
Expand All @@ -15,8 +16,8 @@ class Field extends Element {
this.unique = unique;
this.pk = pk;
this.not_null = notNull;
this.note = note ? note.value : null;
this.noteToken = note ? note.token : null;
this.note = note ? get(note, 'value', note) : null;
this.noteToken = note ? get(note, 'token', noteToken) : null;
this.dbdefault = dbdefault;
this.increment = increment;
this.endpoints = [];
Expand Down
7 changes: 4 additions & 3 deletions packages/dbml-core/src/model_structure/schema.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { get } from 'lodash';
import Table from './table';
import Element from './element';
import Enum from './enum';
Expand All @@ -7,16 +8,16 @@ import Ref from './ref';

class Schema extends Element {
constructor ({
name, alias, note, tables = [], refs = [], enums = [], tableGroups = [], token, database = {},
name, alias, note, tables = [], refs = [], enums = [], tableGroups = [], token, database = {}, noteToken = null,
} = {}) {
super(token);
this.tables = [];
this.enums = [];
this.tableGroups = [];
this.refs = [];
this.name = name;
this.note = note ? note.value : null;
this.noteToken = note ? note.token : null;
this.note = note ? get(note, 'value', note) : null;
this.noteToken = note ? get(note, 'token', noteToken) : null;
this.alias = alias;
this.database = database;
this.dbState = this.database.dbState;
Expand Down
7 changes: 4 additions & 3 deletions packages/dbml-core/src/model_structure/table.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { get } from 'lodash';
import Element from './element';
import Field from './field';
import Index from './indexes';
Expand All @@ -6,13 +7,13 @@ import { shouldPrintSchema } from './utils';

class Table extends Element {
constructor ({
name, alias, note, fields = [], indexes = [], schema = {}, token, headerColor,
name, alias, note, fields = [], indexes = [], schema = {}, token, headerColor, noteToken = null,
} = {}) {
super(token);
this.name = name;
this.alias = alias;
this.note = note ? note.value : null;
this.noteToken = note ? note.token : null;
this.note = note ? get(note, 'value', note) : null;
this.noteToken = note ? get(note, 'token', noteToken) : null;
this.headerColor = headerColor;
this.fields = [];
this.indexes = [];
Expand Down
Loading