@dbml/core 2.4.2 → 2.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -59,6 +59,13 @@ data_type "VALID TYPE" = c1:"CHARACTER"i _ c2:"VARYING"i _ args:("("expression")
59
59
  args: args ? args[1] : null
60
60
  }
61
61
  }
62
+ / "timestamptz"i _ number:("(" _ numeric_constant _ ")" _)? dimensions:(array_extension)? {
63
+ const args = number ? number[2] : null;
64
+ return {
65
+ type_name: (args !== null ? `timestamptz(${args})`: `timestamptz`) + (dimensions ? dimensions.map((dimension) => '[' + dimension + ']').join('') : ''),
66
+ args
67
+ }
68
+ }
62
69
  / "timestamp"i _ number:("(" _ numeric_constant _ ")" _)? (("without"i/"with"i) _ "time"i _ "zone"i)? dimensions:(array_extension)? {
63
70
  const args = number ? number[2] : null;
64
71
  return {
@@ -66,6 +73,13 @@ data_type "VALID TYPE" = c1:"CHARACTER"i _ c2:"VARYING"i _ args:("("expression")
66
73
  args
67
74
  }
68
75
  }
76
+ / "timetz"i _ number:("(" _ numeric_constant _ ")" _)? dimensions:(array_extension)? {
77
+ const args = number ? number[2] : null;
78
+ return {
79
+ type_name: (args !== null ? `timetz(${args})`: `timetz`) + (dimensions ? dimensions.map((dimension) => '[' + dimension + ']').join('') : ''),
80
+ args
81
+ }
82
+ }
69
83
  / "time"i _ number:("(" _ numeric_constant _ ")" _)? (("without"i/"with"i) _ "time"i _ "zone"i)? dimensions:(array_extension)? {
70
84
  const args = number ? number[2] : null;
71
85
  return {
@@ -87,6 +101,7 @@ data_type "VALID TYPE" = c1:"CHARACTER"i _ c2:"VARYING"i _ args:("("expression")
87
101
  args: null
88
102
  }
89
103
  }
104
+
90
105
  type_name = pathName:path_name? c:(character)+ _ args:("(" expression ")")? {
91
106
  let type_name = c.join("");
92
107
  args = args ? args[1] : null;
@@ -1,4 +1,4 @@
1
- create_table_normal =
1
+ create_table_normal =
2
2
  _ CREATE __ ( ( GLOBAL __ / LOCAL __ )? ( TEMPORARY / TEMP ) __ / UNLOGGED __)? TABLE (__ IF_NOT_EXISTS)? __ table_name:table_name _ "(" _
3
3
  table_properties:table_properties _ ")"
4
4
  (__ INHERITS _ "(" _ parent_tables:table_names _ ")")?
@@ -56,6 +56,7 @@ create_table_normal =
56
56
  field.inline_refs = [];
57
57
  }
58
58
  field.inline_refs.push({
59
+ name: ref.name,
59
60
  endpoint: ref.endpoints[1],
60
61
  onDelete: ref.onDelete,
61
62
  onUpdate: ref.onUpdate
@@ -78,7 +79,7 @@ table_properties = first:table_property rest: (_ comma _ table_property)* {
78
79
  return [first, ...rest.map(r => r[3])];
79
80
  }
80
81
 
81
- table_property =
82
+ table_property =
82
83
  table_constraint:table_constraint {
83
84
  return {
84
85
  table_property_name: "table_constraint",
@@ -93,13 +94,12 @@ table_property =
93
94
  }
94
95
  / column_name:column_name __ data_type:data_type (__ COLLATE __ collation:identifier)? column_constraints:(_ column_constraint)* {
95
96
  const column = { name: column_name , type: data_type};
96
-
97
- // process type (if type === "serial")
98
- if (column.type.type_name.toLowerCase() === "serial") {
99
- column.type.type_name = "int";
97
+ const columnTypeName = column.type.type_name.toLowerCase();
98
+ const serialIncrementType = new Set(['serial', 'smallserial', 'bigserial']);
99
+ // process type for increment
100
+ if (serialIncrementType.has(columnTypeName)) {
100
101
  column.increment = true;
101
102
  }
102
-
103
103
  // map from grammar to right object
104
104
  column_constraints = column_constraints.map(c => c[1]);
105
105
  // process column_constraints
@@ -108,6 +108,9 @@ table_property =
108
108
  case "not_null":
109
109
  column.not_null = value;
110
110
  break;
111
+ case "increment":
112
+ column.increment = true;
113
+ break;
111
114
  case "dbdefault":
112
115
  column.dbdefault = value;
113
116
  break;
@@ -132,12 +135,12 @@ table_property =
132
135
  }
133
136
 
134
137
  // return { type, value}
135
- column_constraint = (CONSTRAINT __ constraint_name:identifier __)?
138
+ column_constraint = constraint_name:(CONSTRAINT __ constraint_name:identifier __ { return constraint_name })?
136
139
  column_constraint:( NOT __ NULL { return { type: "not_null" , value: true } }
137
140
  / NULL { return { type: "not_null" , value: false } }
138
141
  / CHECK _ "("_ expression _")" (__ NO __ INHERIT)? { return { type: "not_supported" } }
139
142
  / DEFAULT __ default_expr:default_expr { return { type: "dbdefault", value: default_expr } }
140
- / GENERATED __ (ALWAYS/ BY __ DEFAULT) __ AS __ IDENTITY { return { type: "not_supported" } } // (_ "("_ sequence_options _ ")")? { return { type: "not_supported" } }
143
+ / GENERATED __ (ALWAYS/ BY __ DEFAULT) __ AS __ IDENTITY { return { type: "increment" } } // (_ "("_ sequence_options _ ")")? { return { type: "not_supported" } }
141
144
  / UNIQUE (__ index_parameters)? { return { type: "unique" } }
142
145
  / PRIMARY_KEY (__ index_parameters)? { return { type: "pk" } }
143
146
  / REFERENCES __ reftable:table_name refcolumn:(_ "(" _ refcolumn:column_name _ ")" {return refcolumn})? (__ MATCH __ FULL/__ MATCH __ PARTIAL/__ MATCH __ SIMPLE)?
@@ -155,6 +158,7 @@ column_constraint = (CONSTRAINT __ constraint_name:identifier __)?
155
158
  return {
156
159
  type: "fk",
157
160
  value: {
161
+ name: constraint_name,
158
162
  endpoint: {
159
163
  tableName: reftable.name,
160
164
  schemaName: reftable.schemaName,
@@ -170,7 +174,7 @@ column_constraint = (CONSTRAINT __ constraint_name:identifier __)?
170
174
  }
171
175
 
172
176
  // return { type, t_value }
173
- table_constraint = (CONSTRAINT __ constraint_name:identifier __)?
177
+ table_constraint = constraint_name:(CONSTRAINT __ constraint_name:identifier __ { return constraint_name })?
174
178
  table_constraint: ( CHECK _ "("_ expression _")" (__ NO __ INHERIT)? { return { type:"not_supported" } }
175
179
  / UNIQUE _ "(" _ column_names:column_names _ ")" (__ index_parameters)? { return { type: "unique", t_value: column_names } }
176
180
  / PRIMARY_KEY _ "("_ column_names:column_names _ ")" (__ index_parameters)? { return { type: "pk", t_value: column_names } }
@@ -186,6 +190,7 @@ table_constraint = (CONSTRAINT __ constraint_name:identifier __)?
186
190
  //throw Error(`Line ${location().start.line}: ${column_name} do not have referenced column.`)
187
191
  //}
188
192
  const v = {
193
+ name: constraint_name,
189
194
  endpoints: [
190
195
  {
191
196
  tableName: null,
@@ -210,7 +215,7 @@ table_constraint = (CONSTRAINT __ constraint_name:identifier __)?
210
215
  value.push(v);
211
216
  return {
212
217
  type: "fk",
213
- t_value: value
218
+ t_value: value
214
219
  }
215
220
  }
216
221
  ) (__ DEFERRABLE /__ NOT __ DEFERRABLE)? (__ INITIALLY __ DEFERRED /__ INITIALLY __ IMMEDIATE)? {
@@ -22,6 +22,7 @@ parser = commands:command* {
22
22
  if (field.inline_refs) {
23
23
  refs.push(...field.inline_refs.map(ref => {
24
24
  return {
25
+ name: ref.name,
25
26
  endpoints: [
26
27
  {
27
28
  tableName: table.name,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dbml/core",
3
- "version": "2.4.2",
3
+ "version": "2.4.4",
4
4
  "description": "> TODO: description",
5
5
  "author": "Holistics <dev@holistics.io>",
6
6
  "license": "Apache-2.0",
@@ -56,5 +56,5 @@
56
56
  "\\.(?!json$)[^.]*$": "jest-raw-loader"
57
57
  }
58
58
  },
59
- "gitHead": "2d33941ba6f0833254bfc434abed1dc59f8f2b87"
59
+ "gitHead": "39107aef57e41d29378ba15abe0c7057f7c5be00"
60
60
  }