mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-22 00:40:22 +02:00
feat(er): add UK attribute constraint
Any attribute can now be PK, FK or UK
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">
|
||||||
|
@@ -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 () {
|
||||||
|
Reference in New Issue
Block a user