UNPKG

sequelize

Version:

Multi dialect ORM for Node.JS/io.js

1,497 lines (1,496 loc) 1.54 MB
{ "type": "File", "start": 0, "end": 8175, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 257, "column": 0 } }, "program": { "type": "Program", "start": 0, "end": 8175, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 257, "column": 0 } }, "sourceType": "module", "body": [ { "type": "VariableDeclaration", "start": 15, "end": 51, "loc": { "start": { "line": 3, "column": 0 }, "end": { "line": 3, "column": 36 } }, "declarations": [ { "type": "VariableDeclarator", "start": 21, "end": 50, "loc": { "start": { "line": 3, "column": 6 }, "end": { "line": 3, "column": 35 } }, "id": { "type": "Identifier", "start": 21, "end": 26, "loc": { "start": { "line": 3, "column": 6 }, "end": { "line": 3, "column": 11 }, "identifierName": "Utils" }, "name": "Utils" }, "init": { "type": "CallExpression", "start": 29, "end": 50, "loc": { "start": { "line": 3, "column": 14 }, "end": { "line": 3, "column": 35 } }, "callee": { "type": "Identifier", "start": 29, "end": 36, "loc": { "start": { "line": 3, "column": 14 }, "end": { "line": 3, "column": 21 }, "identifierName": "require" }, "name": "require" }, "arguments": [ { "type": "StringLiteral", "start": 37, "end": 49, "loc": { "start": { "line": 3, "column": 22 }, "end": { "line": 3, "column": 34 } }, "extra": { "rawValue": "./../utils", "raw": "'./../utils'" }, "value": "./../utils" } ] } } ], "kind": "const" }, { "type": "VariableDeclaration", "start": 52, "end": 89, "loc": { "start": { "line": 4, "column": 0 }, "end": { "line": 4, "column": 37 } }, "declarations": [ { "type": "VariableDeclarator", "start": 58, "end": 88, "loc": { "start": { "line": 4, "column": 6 }, "end": { "line": 4, "column": 36 } }, "id": { "type": "Identifier", "start": 58, "end": 65, "loc": { "start": { "line": 4, "column": 6 }, "end": { "line": 4, "column": 13 }, "identifierName": "Helpers" }, "name": "Helpers" }, "init": { "type": "CallExpression", "start": 68, "end": 88, "loc": { "start": { "line": 4, "column": 16 }, "end": { "line": 4, "column": 36 } }, "callee": { "type": "Identifier", "start": 68, "end": 75, "loc": { "start": { "line": 4, "column": 16 }, "end": { "line": 4, "column": 23 }, "identifierName": "require" }, "name": "require" }, "arguments": [ { "type": "StringLiteral", "start": 76, "end": 87, "loc": { "start": { "line": 4, "column": 24 }, "end": { "line": 4, "column": 35 } }, "extra": { "rawValue": "./helpers", "raw": "'./helpers'" }, "value": "./helpers" } ] } } ], "kind": "const" }, { "type": "VariableDeclaration", "start": 90, "end": 118, "loc": { "start": { "line": 5, "column": 0 }, "end": { "line": 5, "column": 28 } }, "declarations": [ { "type": "VariableDeclarator", "start": 96, "end": 117, "loc": { "start": { "line": 5, "column": 6 }, "end": { "line": 5, "column": 27 } }, "id": { "type": "Identifier", "start": 96, "end": 97, "loc": { "start": { "line": 5, "column": 6 }, "end": { "line": 5, "column": 7 }, "identifierName": "_" }, "name": "_" }, "init": { "type": "CallExpression", "start": 100, "end": 117, "loc": { "start": { "line": 5, "column": 10 }, "end": { "line": 5, "column": 27 } }, "callee": { "type": "Identifier", "start": 100, "end": 107, "loc": { "start": { "line": 5, "column": 10 }, "end": { "line": 5, "column": 17 }, "identifierName": "require" }, "name": "require" }, "arguments": [ { "type": "StringLiteral", "start": 108, "end": 116, "loc": { "start": { "line": 5, "column": 18 }, "end": { "line": 5, "column": 26 } }, "extra": { "rawValue": "lodash", "raw": "'lodash'" }, "value": "lodash" } ] } } ], "kind": "const" }, { "type": "VariableDeclaration", "start": 119, "end": 157, "loc": { "start": { "line": 6, "column": 0 }, "end": { "line": 6, "column": 38 } }, "declarations": [ { "type": "VariableDeclarator", "start": 125, "end": 156, "loc": { "start": { "line": 6, "column": 6 }, "end": { "line": 6, "column": 37 } }, "id": { "type": "Identifier", "start": 125, "end": 136, "loc": { "start": { "line": 6, "column": 6 }, "end": { "line": 6, "column": 17 }, "identifierName": "Association" }, "name": "Association" }, "init": { "type": "CallExpression", "start": 139, "end": 156, "loc": { "start": { "line": 6, "column": 20 }, "end": { "line": 6, "column": 37 } }, "callee": { "type": "Identifier", "start": 139, "end": 146, "loc": { "start": { "line": 6, "column": 20 }, "end": { "line": 6, "column": 27 }, "identifierName": "require" }, "name": "require" }, "arguments": [ { "type": "StringLiteral", "start": 147, "end": 155, "loc": { "start": { "line": 6, "column": 28 }, "end": { "line": 6, "column": 36 } }, "extra": { "rawValue": "./base", "raw": "'./base'" }, "value": "./base" } ] } } ], "kind": "const", "trailingComments": [ { "type": "CommentBlock", "value": "*\n * One-to-one association\n *\n * In the API reference below, add the name of the association to the method, e.g. for `User.hasOne(Project)` the getter will be `user.getProject()`.\n * This is almost the same as `belongsTo` with one exception - The foreign key will be defined on the target model.\n *\n * @see {@link Model.hasOne}\n ", "start": 159, "end": 493, "loc": { "start": { "line": 8, "column": 0 }, "end": { "line": 15, "column": 3 } } } ] }, { "type": "ClassDeclaration", "start": 494, "end": 8148, "loc": { "start": { "line": 16, "column": 0 }, "end": { "line": 254, "column": 1 } }, "id": { "type": "Identifier", "start": 500, "end": 506, "loc": { "start": { "line": 16, "column": 6 }, "end": { "line": 16, "column": 12 }, "identifierName": "HasOne" }, "name": "HasOne", "leadingComments": null }, "superClass": { "type": "Identifier", "start": 515, "end": 526, "loc": { "start": { "line": 16, "column": 21 }, "end": { "line": 16, "column": 32 }, "identifierName": "Association" }, "name": "Association" }, "body": { "type": "ClassBody", "start": 527, "end": 8148, "loc": { "start": { "line": 16, "column": 33 }, "end": { "line": 254, "column": 1 } }, "body": [ { "type": "ClassMethod", "start": 531, "end": 2300, "loc": { "start": { "line": 17, "column": 2 }, "end": { "line": 70, "column": 3 } }, "computed": false, "key": { "type": "Identifier", "start": 531, "end": 542, "loc": { "start": { "line": 17, "column": 2 }, "end": { "line": 17, "column": 13 }, "identifierName": "constructor" }, "name": "constructor" }, "static": false, "kind": "constructor", "id": null, "generator": false, "expression": false, "async": false, "params": [ { "type": "Identifier", "start": 543, "end": 549, "loc": { "start": { "line": 17, "column": 14 }, "end": { "line": 17, "column": 20 }, "identifierName": "source" }, "name": "source" }, { "type": "Identifier", "start": 551, "end": 557, "loc": { "start": { "line": 17, "column": 22 }, "end": { "line": 17, "column": 28 }, "identifierName": "target" }, "name": "target" }, { "type": "Identifier", "start": 559, "end": 566, "loc": { "start": { "line": 17, "column": 30 }, "end": { "line": 17, "column": 37 }, "identifierName": "options" }, "name": "options" } ], "body": { "type": "BlockStatement", "start": 568, "end": 2300, "loc": { "start": { "line": 17, "column": 39 }, "end": { "line": 70, "column": 3 } }, "body": [ { "type": "ExpressionStatement", "start": 574, "end": 605, "loc": { "start": { "line": 18, "column": 4 }, "end": { "line": 18, "column": 35 } }, "expression": { "type": "CallExpression", "start": 574, "end": 604, "loc": { "start": { "line": 18, "column": 4 }, "end": { "line": 18, "column": 34 } }, "callee": { "type": "Super", "start": 574, "end": 579, "loc": { "start": { "line": 18, "column": 4 }, "end": { "line": 18, "column": 9 } } }, "arguments": [ { "type": "Identifier", "start": 580, "end": 586, "loc": { "start": { "line": 18, "column": 10 }, "end": { "line": 18, "column": 16 }, "identifierName": "source" }, "name": "source" }, { "type": "Identifier", "start": 588, "end": 594, "loc": { "start": { "line": 18, "column": 18 }, "end": { "line": 18, "column": 24 }, "identifierName": "target" }, "name": "target" }, { "type": "Identifier", "start": 596, "end": 603, "loc": { "start": { "line": 18, "column": 26 }, "end": { "line": 18, "column": 33 }, "identifierName": "options" }, "name": "options" } ] } }, { "type": "ExpressionStatement", "start": 611, "end": 643, "loc": { "start": { "line": 20, "column": 4 }, "end": { "line": 20, "column": 36 } }, "expression": { "type": "AssignmentExpression", "start": 611, "end": 642, "loc": { "start": { "line": 20, "column": 4 }, "end": { "line": 20, "column": 35 } }, "operator": "=", "left": { "type": "MemberExpression", "start": 611, "end": 631, "loc": { "start": { "line": 20, "column": 4 }, "end": { "line": 20, "column": 24 } }, "object": { "type": "ThisExpression", "start": 611, "end": 615, "loc": { "start": { "line": 20, "column": 4 }, "end": { "line": 20, "column": 8 } } }, "property": { "type": "Identifier", "start": 616, "end": 631, "loc": { "start": { "line": 20, "column": 9 }, "end": { "line": 20, "column": 24 }, "identifierName": "associationType" }, "name": "associationType" }, "computed": false }, "right": { "type": "StringLiteral", "start": 634, "end": 642, "loc": { "start": { "line": 20, "column": 27 }, "end": { "line": 20, "column": 35 } }, "extra": { "rawValue": "HasOne", "raw": "'HasOne'" }, "value": "HasOne" } } }, { "type": "ExpressionStatement", "start": 648, "end": 680, "loc": { "start": { "line": 21, "column": 4 }, "end": { "line": 21, "column": 36 } }, "expression": { "type": "AssignmentExpression", "start": 648, "end": 679, "loc": { "start": { "line": 21, "column": 4 }, "end": { "line": 21, "column": 35 } }, "operator": "=", "left": { "type": "MemberExpression", "start": 648, "end": 672, "loc": { "start": { "line": 21, "column": 4 }, "end": { "line": 21, "column": 28 } }, "object": { "type": "ThisExpression", "start": 648, "end": 652, "loc": { "start": { "line": 21, "column": 4 }, "end": { "line": 21, "column": 8 } } }, "property": { "type": "Identifier", "start": 653, "end": 672, "loc": { "start": { "line": 21, "column": 9 }, "end": { "line": 21, "column": 28 }, "identifierName": "isSingleAssociation" }, "name": "isSingleAssociation" }, "computed": false }, "right": { "type": "BooleanLiteral", "start": 675, "end": 679, "loc": { "start": { "line": 21, "column": 31 }, "end": { "line": 21, "column": 35 } }, "value": true } } }, { "type": "ExpressionStatement", "start": 685, "end": 715, "loc": { "start": { "line": 22, "column": 4 }, "end": { "line": 22, "column": 34 } }, "expression": { "type": "AssignmentExpression", "start": 685, "end": 714, "loc": { "start": { "line": 22, "column": 4 }, "end": { "line": 22, "column": 33 } }, "operator": "=", "left": { "type": "MemberExpression", "start": 685, "end": 709, "loc": { "start": { "line": 22, "column": 4 }, "end": { "line": 22, "column": 28 } }, "object": { "type": "ThisExpression", "start": 685, "end": 689, "loc": { "start": { "line": 22, "column": 4 }, "end": { "line": 22, "column": 8 } } }, "property": { "type": "Identifier", "start": 690, "end": 709, "loc": { "start": { "line": 22, "column": 9 }, "end": { "line": 22, "column": 28 }, "identifierName": "foreignKeyAttribute" }, "name": "foreignKeyAttribute" }, "computed": false }, "right": { "type": "ObjectExpression", "start": 712, "end": 714, "loc": { "start": { "line": 22, "column": 31 }, "end": { "line": 22, "column": 33 } }, "properties": [] } } }, { "type": "IfStatement", "start": 721, "end": 949, "loc": { "start": { "line": 24, "column": 4 }, "end": { "line": 32, "column": 5 } }, "test": { "type": "MemberExpression", "start": 725, "end": 732, "loc": { "start": { "line": 24, "column": 8 }, "end": { "line": 24, "column": 15 } }, "object": { "type": "ThisExpression", "start": 725, "end": 729, "loc": { "start": { "line": 24, "column": 8 }, "end": { "line": 24, "column": 12 } } }, "property": { "type": "Identifier", "start": 730, "end": 732, "loc": { "start": { "line": 24, "column": 13 }, "end": { "line": 24, "column": 15 }, "identifierName": "as" }, "name": "as" }, "computed": false }, "consequent": { "type": "BlockStatement", "start": 734, "end": 833, "loc": { "start": { "line": 24, "column": 17 }, "end": { "line": 29, "column": 5 } }, "body": [ { "type": "ExpressionStatement", "start": 742, "end": 764, "loc": { "start": { "line": 25, "column": 6 }, "end": { "line": 25, "column": 28 } }, "expression": { "type": "AssignmentExpression", "start": 742, "end": 763, "loc": { "start": { "line": 25, "column": 6 }, "end": { "line": 25, "column": 27 } }, "operator": "=", "left": { "type": "MemberExpression", "start": 742, "end": 756, "loc": { "start": { "line": 25, "column": 6 }, "end": { "line": 25, "column": 20 } }, "object": { "type": "ThisExpression", "start": 742, "end": 746, "loc": { "start": { "line": 25, "column": 6 }, "end": { "line": 25, "column": 10 } } }, "property": { "type": "Identifier", "start": 747, "end": 756, "loc": { "start": { "line": 25, "column": 11 }, "end": { "line": 25, "column": 20 }, "identifierName": "isAliased" }, "name": "isAliased" }, "computed": false }, "right": { "type": "BooleanLiteral", "start": 759, "end": 763, "loc": { "start": { "line": 25, "column": 23 }, "end": { "line": 25, "column": 27 } }, "value": true } } }, { "type": "ExpressionStatement", "start": 771, "end": 827, "loc": { "start": { "line": 26, "column": 6 }, "end": { "line": 28, "column": 8 } }, "expression": { "type": "AssignmentExpression", "start": 771, "end": 826, "loc": { "start": { "line": 26, "column": 6 }, "end": { "line": 28, "column": 7 } }, "operator": "=", "left": { "type": "MemberExpression", "start": 771, "end": 788, "loc": { "start": { "line": 26, "column": 6 }, "end": { "line": 26, "column": 23 } }, "object": { "type": "MemberExpression", "start": 771, "end": 783, "loc": { "start": { "line": 26, "column": 6 }, "end": { "line": 26, "column": 18 } }, "object": { "type": "ThisExpression", "start": 771, "end": 775, "loc": { "start": { "line": 26, "column": 6 }, "end": { "line": 26, "column": 10 } } }, "property": { "type": "Identifier", "start": 776, "end": 783, "loc": { "start": { "line": 26, "column": 11 }, "end": { "line": 26, "column": 18 }, "identifierName": "options" }, "name": "options" }, "computed": false }, "property": { "type": "Identifier", "start": 784, "end": 788, "loc": { "start": { "line": 26, "column": 19 }, "end": { "line": 26, "column": 23 }, "identifierName": "name" }, "name": "name" }, "computed": false }, "right": { "type": "ObjectExpression", "start": 791, "end": 826, "loc": { "start": { "line": 26, "column": 26 }, "end": { "line": 28, "column": 7 } }, "properties": [ { "type": "ObjectProperty", "start": 801, "end": 818, "loc": { "start": { "line": 27, "column": 8 }, "end": { "line": 27, "column": 25 } }, "method": false, "shorthand": false, "computed": false, "key": { "type": "Identifier", "start": 801, "end": 809, "loc": { "start": { "line": 27, "column": 8 }, "end": { "line": 27, "column": 16 }, "identifierName": "singular" }, "name": "singular" }, "value": { "type": "MemberExpression", "start": 811, "end": 818, "loc": { "start": { "line": 27, "column": 18 }, "end": { "line": 27, "column": 25 } }, "object": { "type": "ThisExpression", "start": 811, "end": 815, "loc": { "start": { "line": 27, "column": 18 }, "end": { "line": 27, "column": 22 } } }, "property": { "type": "Identifier", "start": 816, "end": 818, "loc": { "start": { "line": 27, "column": 23 }, "end": { "line": 27, "column": 25 }, "identifierName": "as" }, "name": "as" }, "computed": false } } ] } } } ], "directives": [] }, "alternate": { "type": "BlockStatement", "start": 839, "end": 949, "loc": { "start": { "line": 29, "column": 11 }, "end": { "line": 32, "column": 5 } }, "body": [ { "type": "ExpressionStatement", "start": 847, "end": 891, "loc": { "start": { "line": 30, "column": 6 }, "end": { "line": 30, "column": 50 } }, "expression": { "type": "AssignmentExpression", "start": 847, "end": 890, "loc": { "start": { "line": 30, "column": 6 }, "end": { "line": 30, "column": 49 } }, "operator": "=", "left": { "type": "MemberExpression", "start": 847, "end": 854, "loc": { "start": { "line": 30, "column": 6 }, "end": { "line": 30, "column": 13 } }, "object": { "type": "ThisExpression", "start": 847, "end": 851, "loc": { "start": { "line": 30, "column": 6 }, "end": { "line": 30, "column": 10 } } }, "property": { "type": "Identifier", "start": 852, "end": 854, "loc": { "start": { "line": 30, "column": 11 }, "end": { "line": 30, "column": 13 }, "identifierName": "as" },