mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-11 11:29:42 +02:00
Merge pull request #3917 from tomperr/feature/3910_er_unique_key
feat(er): add unique key
This commit is contained in:
@@ -57,6 +57,20 @@ erDiagram
|
|||||||
number final_price
|
number final_price
|
||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
|
<hr />
|
||||||
|
|
||||||
|
<pre class="mermaid">
|
||||||
|
erDiagram
|
||||||
|
"HOSPITAL" {
|
||||||
|
int id PK
|
||||||
|
int doctor_id FK
|
||||||
|
string address UK
|
||||||
|
string name
|
||||||
|
string phone_number
|
||||||
|
string fax_number
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
|
<hr />
|
||||||
|
|
||||||
<script src="./mermaid.js"></script>
|
<script src="./mermaid.js"></script>
|
||||||
<script type="module">
|
<script type="module">
|
||||||
|
@@ -234,14 +234,14 @@ The `type` and `name` values must begin with an alphabetic character and may con
|
|||||||
|
|
||||||
#### Attribute Keys and Comments
|
#### Attribute Keys and Comments
|
||||||
|
|
||||||
Attributes may also have a `key` or comment defined. Keys can be "PK" or "FK", for Primary Key or Foreign Key. And a `comment` is defined by double quotes at the end of an attribute. Comments themselves cannot have double-quote characters in them.
|
Attributes may also have a `key` or comment defined. Keys can be "PK", "FK" or "UK", for Primary Key, Foreign Key or Unique Key. And a `comment` is defined by double quotes at the end of an attribute. Comments themselves cannot have double-quote characters in them.
|
||||||
|
|
||||||
```mermaid-example
|
```mermaid-example
|
||||||
erDiagram
|
erDiagram
|
||||||
CAR ||--o{ NAMED-DRIVER : allows
|
CAR ||--o{ NAMED-DRIVER : allows
|
||||||
CAR {
|
CAR {
|
||||||
string allowedDriver FK "The license of the allowed driver"
|
string allowedDriver FK "The license of the allowed driver"
|
||||||
string registrationNumber
|
string registrationNumber UK
|
||||||
string make
|
string make
|
||||||
string model
|
string model
|
||||||
string[] parts
|
string[] parts
|
||||||
@@ -261,7 +261,7 @@ erDiagram
|
|||||||
CAR ||--o{ NAMED-DRIVER : allows
|
CAR ||--o{ NAMED-DRIVER : allows
|
||||||
CAR {
|
CAR {
|
||||||
string allowedDriver FK "The license of the allowed driver"
|
string allowedDriver FK "The license of the allowed driver"
|
||||||
string registrationNumber
|
string registrationNumber UK
|
||||||
string make
|
string make
|
||||||
string model
|
string model
|
||||||
string[] parts
|
string[] parts
|
||||||
|
@@ -29,7 +29,7 @@ accDescr\s*"{"\s* { this.begin("acc_descr_multili
|
|||||||
"erDiagram" return 'ER_DIAGRAM';
|
"erDiagram" return 'ER_DIAGRAM';
|
||||||
"{" { this.begin("block"); return 'BLOCK_START'; }
|
"{" { this.begin("block"); return 'BLOCK_START'; }
|
||||||
<block>\s+ /* skip whitespace in block */
|
<block>\s+ /* skip whitespace in block */
|
||||||
<block>\b((?:PK)|(?:FK))\b return 'ATTRIBUTE_KEY'
|
<block>\b((?:PK)|(?:FK)|(?:UK))\b return 'ATTRIBUTE_KEY'
|
||||||
<block>(.*?)[~](.*?)*[~] return 'ATTRIBUTE_WORD';
|
<block>(.*?)[~](.*?)*[~] return 'ATTRIBUTE_WORD';
|
||||||
<block>[A-Za-z][A-Za-z0-9\-_\[\]\(\)]* return 'ATTRIBUTE_WORD'
|
<block>[A-Za-z][A-Za-z0-9\-_\[\]\(\)]* return 'ATTRIBUTE_WORD'
|
||||||
<block>\"[^"]*\" return 'COMMENT';
|
<block>\"[^"]*\" return 'COMMENT';
|
||||||
|
@@ -176,17 +176,18 @@ describe('when parsing ER diagram it...', function () {
|
|||||||
expect(entities[entity].attributes.length).toBe(1);
|
expect(entities[entity].attributes.length).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should allow an entity with attribute starting with fk or pk and a comment', function () {
|
it('should allow an entity with attribute starting with fk, pk or uk and a comment', function () {
|
||||||
const entity = 'BOOK';
|
const entity = 'BOOK';
|
||||||
const attribute1 = 'int fk_title FK';
|
const attribute1 = 'int fk_title FK';
|
||||||
const attribute2 = 'string pk_author PK';
|
const attribute2 = 'string pk_author PK';
|
||||||
const attribute3 = 'float pk_price PK "comment"';
|
const attribute3 = 'string uk_address UK';
|
||||||
|
const attribute4 = 'float pk_price PK "comment"';
|
||||||
|
|
||||||
erDiagram.parser.parse(
|
erDiagram.parser.parse(
|
||||||
`erDiagram\n${entity} {\n${attribute1} \n\n${attribute2}\n${attribute3}\n}`
|
`erDiagram\n${entity} {\n${attribute1} \n\n${attribute2}\n${attribute3}\n${attribute4}\n}`
|
||||||
);
|
);
|
||||||
const entities = erDb.getEntities();
|
const entities = erDb.getEntities();
|
||||||
expect(entities[entity].attributes.length).toBe(3);
|
expect(entities[entity].attributes.length).toBe(4);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should allow an entity with attribute that has a generic type', function () {
|
it('should allow an entity with attribute that has a generic type', function () {
|
||||||
|
@@ -164,14 +164,14 @@ The `type` and `name` values must begin with an alphabetic character and may con
|
|||||||
|
|
||||||
#### Attribute Keys and Comments
|
#### Attribute Keys and Comments
|
||||||
|
|
||||||
Attributes may also have a `key` or comment defined. Keys can be "PK" or "FK", for Primary Key or Foreign Key. And a `comment` is defined by double quotes at the end of an attribute. Comments themselves cannot have double-quote characters in them.
|
Attributes may also have a `key` or comment defined. Keys can be "PK", "FK" or "UK", for Primary Key, Foreign Key or Unique Key. And a `comment` is defined by double quotes at the end of an attribute. Comments themselves cannot have double-quote characters in them.
|
||||||
|
|
||||||
```mermaid-example
|
```mermaid-example
|
||||||
erDiagram
|
erDiagram
|
||||||
CAR ||--o{ NAMED-DRIVER : allows
|
CAR ||--o{ NAMED-DRIVER : allows
|
||||||
CAR {
|
CAR {
|
||||||
string allowedDriver FK "The license of the allowed driver"
|
string allowedDriver FK "The license of the allowed driver"
|
||||||
string registrationNumber
|
string registrationNumber UK
|
||||||
string make
|
string make
|
||||||
string model
|
string model
|
||||||
string[] parts
|
string[] parts
|
||||||
|
Reference in New Issue
Block a user