UNPKG

sequelize

Version:

Multi dialect ORM for Node.JS/io.js

1,664 lines (1,663 loc) 344 kB
{ "type": "File", "start": 0, "end": 3219, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 124, "column": 0 } }, "program": { "type": "Program", "start": 0, "end": 3219, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 124, "column": 0 } }, "sourceType": "module", "body": [ { "type": "VariableDeclaration", "start": 15, "end": 42, "loc": { "start": { "line": 3, "column": 0 }, "end": { "line": 3, "column": 27 } }, "declarations": [ { "type": "VariableDeclarator", "start": 19, "end": 41, "loc": { "start": { "line": 3, "column": 4 }, "end": { "line": 3, "column": 26 } }, "id": { "type": "Identifier", "start": 19, "end": 23, "loc": { "start": { "line": 3, "column": 4 }, "end": { "line": 3, "column": 8 }, "identifierName": "util" }, "name": "util" }, "init": { "type": "CallExpression", "start": 26, "end": 41, "loc": { "start": { "line": 3, "column": 11 }, "end": { "line": 3, "column": 26 } }, "callee": { "type": "Identifier", "start": 26, "end": 33, "loc": { "start": { "line": 3, "column": 11 }, "end": { "line": 3, "column": 18 }, "identifierName": "require" }, "name": "require" }, "arguments": [ { "type": "StringLiteral", "start": 34, "end": 40, "loc": { "start": { "line": 3, "column": 19 }, "end": { "line": 3, "column": 25 } }, "extra": { "rawValue": "util", "raw": "'util'" }, "value": "util" } ] } } ], "kind": "var", "trailingComments": [ { "type": "CommentBlock", "value": "*\n * A collection of properties related to deferrable constraints. It can be used to\n * make foreign key constraints deferrable and to set the constraints within a\n * transaction. This is only supported in PostgreSQL.\n *\n * The foreign keys can be configured like this. It will create a foreign key\n * that will check the constraints immediately when the data was inserted.\n *\n * ```js\n * sequelize.define('Model', {\n * foreign_id: {\n * type: Sequelize.INTEGER,\n * references: {\n * model: OtherModel,\n * key: 'id',\n * deferrable: Sequelize.Deferrable.INITIALLY_IMMEDIATE\n * }\n * }\n * });\n * ```\n *\n * The constraints can be configured in a transaction like this. It will\n * trigger a query once the transaction has been started and set the constraints\n * to be checked at the very end of the transaction.\n *\n * ```js\n * sequelize.transaction({\n * deferrable: Sequelize.Deferrable.SET_DEFERRED\n * });\n * ```\n *\n * @property INITIALLY_DEFERRED Defer constraints checks to the end of transactions.\n * @property INITIALLY_IMMEDIATE Trigger the constraint checks immediately\n * @property NOT Set the constraints to not deferred. This is the default in PostgreSQL and it make it impossible to dynamically defer the constraints within a transaction.\n * @property SET_DEFERRED\n * @property SET_IMMEDIATE\n ", "start": 45, "end": 1382, "loc": { "start": { "line": 6, "column": 0 }, "end": { "line": 42, "column": 3 } } } ] }, { "type": "VariableDeclaration", "start": 1383, "end": 1505, "loc": { "start": { "line": 43, "column": 0 }, "end": { "line": 49, "column": 2 } }, "declarations": [ { "type": "VariableDeclarator", "start": 1387, "end": 1504, "loc": { "start": { "line": 43, "column": 4 }, "end": { "line": 49, "column": 1 } }, "id": { "type": "Identifier", "start": 1387, "end": 1397, "loc": { "start": { "line": 43, "column": 4 }, "end": { "line": 43, "column": 14 }, "identifierName": "Deferrable" }, "name": "Deferrable", "leadingComments": null }, "init": { "type": "AssignmentExpression", "start": 1400, "end": 1504, "loc": { "start": { "line": 43, "column": 17 }, "end": { "line": 49, "column": 1 } }, "operator": "=", "left": { "type": "MemberExpression", "start": 1400, "end": 1414, "loc": { "start": { "line": 43, "column": 17 }, "end": { "line": 43, "column": 31 } }, "object": { "type": "Identifier", "start": 1400, "end": 1406, "loc": { "start": { "line": 43, "column": 17 }, "end": { "line": 43, "column": 23 }, "identifierName": "module" }, "name": "module" }, "property": { "type": "Identifier", "start": 1407, "end": 1414, "loc": { "start": { "line": 43, "column": 24 }, "end": { "line": 43, "column": 31 }, "identifierName": "exports" }, "name": "exports" }, "computed": false }, "right": { "type": "ObjectExpression", "start": 1417, "end": 1504, "loc": { "start": { "line": 43, "column": 34 }, "end": { "line": 49, "column": 1 } }, "properties": [ { "type": "ObjectProperty", "start": 1421, "end": 1439, "loc": { "start": { "line": 44, "column": 2 }, "end": { "line": 44, "column": 20 } }, "method": false, "shorthand": true, "computed": false, "key": { "type": "Identifier", "start": 1421, "end": 1439, "loc": { "start": { "line": 44, "column": 2 }, "end": { "line": 44, "column": 20 }, "identifierName": "INITIALLY_DEFERRED" }, "name": "INITIALLY_DEFERRED" }, "value": { "type": "Identifier", "start": 1421, "end": 1439, "loc": { "start": { "line": 44, "column": 2 }, "end": { "line": 44, "column": 20 }, "identifierName": "INITIALLY_DEFERRED" }, "name": "INITIALLY_DEFERRED" }, "extra": { "shorthand": true } }, { "type": "ObjectProperty", "start": 1443, "end": 1462, "loc": { "start": { "line": 45, "column": 2 }, "end": { "line": 45, "column": 21 } }, "method": false, "shorthand": true, "computed": false, "key": { "type": "Identifier", "start": 1443, "end": 1462, "loc": { "start": { "line": 45, "column": 2 }, "end": { "line": 45, "column": 21 }, "identifierName": "INITIALLY_IMMEDIATE" }, "name": "INITIALLY_IMMEDIATE" }, "value": { "type": "Identifier", "start": 1443, "end": 1462, "loc": { "start": { "line": 45, "column": 2 }, "end": { "line": 45, "column": 21 }, "identifierName": "INITIALLY_IMMEDIATE" }, "name": "INITIALLY_IMMEDIATE" }, "extra": { "shorthand": true } }, { "type": "ObjectProperty", "start": 1466, "end": 1469, "loc": { "start": { "line": 46, "column": 2 }, "end": { "line": 46, "column": 5 } }, "method": false, "shorthand": true, "computed": false, "key": { "type": "Identifier", "start": 1466, "end": 1469, "loc": { "start": { "line": 46, "column": 2 }, "end": { "line": 46, "column": 5 }, "identifierName": "NOT" }, "name": "NOT" }, "value": { "type": "Identifier", "start": 1466, "end": 1469, "loc": { "start": { "line": 46, "column": 2 }, "end": { "line": 46, "column": 5 }, "identifierName": "NOT" }, "name": "NOT" }, "extra": { "shorthand": true } }, { "type": "ObjectProperty", "start": 1473, "end": 1485, "loc": { "start": { "line": 47, "column": 2 }, "end": { "line": 47, "column": 14 } }, "method": false, "shorthand": true, "computed": false, "key": { "type": "Identifier", "start": 1473, "end": 1485, "loc": { "start": { "line": 47, "column": 2 }, "end": { "line": 47, "column": 14 }, "identifierName": "SET_DEFERRED" }, "name": "SET_DEFERRED" }, "value": { "type": "Identifier", "start": 1473, "end": 1485, "loc": { "start": { "line": 47, "column": 2 }, "end": { "line": 47, "column": 14 }, "identifierName": "SET_DEFERRED" }, "name": "SET_DEFERRED" }, "extra": { "shorthand": true } }, { "type": "ObjectProperty", "start": 1489, "end": 1502, "loc": { "start": { "line": 48, "column": 2 }, "end": { "line": 48, "column": 15 } }, "method": false, "shorthand": true, "computed": false, "key": { "type": "Identifier", "start": 1489, "end": 1502, "loc": { "start": { "line": 48, "column": 2 }, "end": { "line": 48, "column": 15 }, "identifierName": "SET_IMMEDIATE" }, "name": "SET_IMMEDIATE" }, "value": { "type": "Identifier", "start": 1489, "end": 1502, "loc": { "start": { "line": 48, "column": 2 }, "end": { "line": 48, "column": 15 }, "identifierName": "SET_IMMEDIATE" }, "name": "SET_IMMEDIATE" }, "extra": { "shorthand": true } } ] } }, "leadingComments": null } ], "kind": "var", "leadingComments": [ { "type": "CommentBlock", "value": "*\n * A collection of properties related to deferrable constraints. It can be used to\n * make foreign key constraints deferrable and to set the constraints within a\n * transaction. This is only supported in PostgreSQL.\n *\n * The foreign keys can be configured like this. It will create a foreign key\n * that will check the constraints immediately when the data was inserted.\n *\n * ```js\n * sequelize.define('Model', {\n * foreign_id: {\n * type: Sequelize.INTEGER,\n * references: {\n * model: OtherModel,\n * key: 'id',\n * deferrable: Sequelize.Deferrable.INITIALLY_IMMEDIATE\n * }\n * }\n * });\n * ```\n *\n * The constraints can be configured in a transaction like this. It will\n * trigger a query once the transaction has been started and set the constraints\n * to be checked at the very end of the transaction.\n *\n * ```js\n * sequelize.transaction({\n * deferrable: Sequelize.Deferrable.SET_DEFERRED\n * });\n * ```\n *\n * @property INITIALLY_DEFERRED Defer constraints checks to the end of transactions.\n * @property INITIALLY_IMMEDIATE Trigger the constraint checks immediately\n * @property NOT Set the constraints to not deferred. This is the default in PostgreSQL and it make it impossible to dynamically defer the constraints within a transaction.\n * @property SET_DEFERRED\n * @property SET_IMMEDIATE\n ", "start": 45, "end": 1382, "loc": { "start": { "line": 6, "column": 0 }, "end": { "line": 42, "column": 3 } } } ] }, { "type": "FunctionDeclaration", "start": 1507, "end": 1529, "loc": { "start": { "line": 51, "column": 0 }, "end": { "line": 51, "column": 22 } }, "id": { "type": "Identifier", "start": 1516, "end": 1524, "loc": { "start": { "line": 51, "column": 9 }, "end": { "line": 51, "column": 17 }, "identifierName": "ABSTRACT" }, "name": "ABSTRACT" }, "generator": false, "expression": false, "async": false, "params": [], "body": { "type": "BlockStatement", "start": 1527, "end": 1529, "loc": { "start": { "line": 51, "column": 20 }, "end": { "line": 51, "column": 22 } }, "body": [], "directives": [] } }, { "type": "ExpressionStatement", "start": 1531, "end": 1620, "loc": { "start": { "line": 53, "column": 0 }, "end": { "line": 55, "column": 2 } }, "expression": { "type": "AssignmentExpression", "start": 1531, "end": 1619, "loc": { "start": { "line": 53, "column": 0 }, "end": { "line": 55, "column": 1 } }, "operator": "=", "left": { "type": "MemberExpression", "start": 1531, "end": 1558, "loc": { "start": { "line": 53, "column": 0 }, "end": { "line": 53, "column": 27 } }, "object": { "type": "MemberExpression", "start": 1531, "end": 1549, "loc": { "start": { "line": 53, "column": 0 }, "end": { "line": 53, "column": 18 } }, "object": { "type": "Identifier", "start": 1531, "end": 1539, "loc": { "start": { "line": 53, "column": 0 }, "end": { "line": 53, "column": 8 }, "identifierName": "ABSTRACT" }, "name": "ABSTRACT" }, "property": { "type": "Identifier", "start": 1540, "end": 1549, "loc": { "start": { "line": 53, "column": 9 }, "end": { "line": 53, "column": 18 }, "identifierName": "prototype" }, "name": "prototype" }, "computed": false }, "property": { "type": "Identifier", "start": 1550, "end": 1558, "loc": { "start": { "line": 53, "column": 19 }, "end": { "line": 53, "column": 27 }, "identifierName": "toString" }, "name": "toString" }, "computed": false }, "right": { "type": "FunctionExpression", "start": 1561, "end": 1619, "loc": { "start": { "line": 53, "column": 30 }, "end": { "line": 55, "column": 1 } }, "id": { "type": "Identifier", "start": 1550, "end": 1558, "loc": { "start": { "line": 53, "column": 19 }, "end": { "line": 53, "column": 27 }, "identifierName": "toString" }, "name": "toString" }, "generator": false, "expression": false, "async": false, "params": [], "body": { "type": "BlockStatement", "start": 1572, "end": 1619, "loc": { "start": { "line": 53, "column": 41 }, "end": { "line": 55, "column": 1 } }, "body": [ { "type": "ReturnStatement", "start": 1576, "end": 1617, "loc": { "start": { "line": 54, "column": 2 }, "end": { "line": 54, "column": 43 } }, "argument": { "type": "CallExpression", "start": 1583, "end": 1616, "loc": { "start": { "line": 54, "column": 9 }, "end": { "line": 54, "column": 42 } }, "callee": { "type": "MemberExpression", "start": 1583, "end": 1599, "loc": { "start": { "line": 54, "column": 9 }, "end": { "line": 54, "column": 25 } }, "object": { "type": "MemberExpression", "start": 1583, "end": 1593, "loc": { "start": { "line": 54, "column": 9 }, "end": { "line": 54, "column": 19 } }, "object": { "type": "ThisExpression", "start": 1583, "end": 1587, "loc": { "start": { "line": 54, "column": 9 }, "end": { "line": 54, "column": 13 } } }, "property": { "type": "Identifier", "start": 1588, "end": 1593, "loc": { "start": { "line": 54, "column": 14 }, "end": { "line": 54, "column": 19 }, "identifierName": "toSql" }, "name": "toSql" }, "computed": false }, "property": { "type": "Identifier", "start": 1594, "end": 1599, "loc": { "start": { "line": 54, "column": 20 }, "end": { "line": 54, "column": 25 }, "identifierName": "apply" }, "name": "apply" }, "computed": false }, "arguments": [ { "type": "ThisExpression", "start": 1600, "end": 1604, "loc": { "start": { "line": 54, "column": 26 }, "end": { "line": 54, "column": 30 } } }, { "type": "Identifier", "start": 1606, "end": 1615, "loc": { "start": { "line": 54, "column": 32 }, "end": { "line": 54, "column": 41 }, "identifierName": "arguments" }, "name": "arguments" } ] } } ], "directives": [] } } } }, { "type": "FunctionDeclaration", "start": 1622, "end": 1743, "loc": { "start": { "line": 57, "column": 0 }, "end": { "line": 61, "column": 1 } }, "id": { "type": "Identifier", "start": 1631, "end": 1649, "loc": { "start": { "line": 57, "column": 9 }, "end": { "line": 57, "column": 27 }, "identifierName": "INITIALLY_DEFERRED" }, "name": "INITIALLY_DEFERRED" }, "generator": false, "expression": false, "async": false, "params": [], "body": { "type": "BlockStatement", "start": 1652, "end": 1743, "loc": { "start": { "line": 57, "column": 30 }, "end": { "line": 61, "column": 1 } }, "body": [ { "type": "IfStatement", "start": 1656, "end": 1741, "loc": { "start": { "line": 58, "column": 2 }, "end": { "line": 60, "column": 3 } }, "test": { "type": "UnaryExpression", "start": 1660, "end": 1697, "loc": { "start": { "line": 58, "column": 6 }, "end": { "line": 58, "column": 43 } }, "operator": "!", "prefix": true, "argument": { "type": "BinaryExpression", "start": 1662, "end": 1696, "loc": { "start": { "line": 58, "column": 8 }, "end": { "line": 58, "column": 42 } }, "left": { "type": "ThisExpression", "start": 1662, "end": 1666, "loc": { "start": { "line": 58, "column": 8 }, "end": { "line": 58, "column": 12 } } }, "operator": "instanceof", "right": { "type": "Identifier", "start": 1678, "end": 1696, "loc": { "start": { "line": 58, "column": 24 }, "end": { "line": 58, "column": 42 }, "identifierName": "INITIALLY_DEFERRED" }, "name": "INITIALLY_DEFERRED" }, "extra": { "parenthesized": true, "parenStart": 1661 } }, "extra": { "parenthesizedArgument": false } }, "consequent": { "type": "BlockStatement", "start": 1699, "end": 1741, "loc": { "start": { "line": 58, "column": 45 }, "end": { "line": 60, "column": 3 } }, "body": [ { "type": "ReturnStatement", "start": 1705, "end": 1737, "loc": { "start": { "line": 59, "column": 4 }, "end": { "line": 59, "column": 36 } }, "argument": { "type": "NewExpression", "start": 1712, "end": 1736, "loc": { "start": { "line": 59, "column": 11 }, "end": { "line": 59, "column": 35 } }, "callee": { "type": "Identifier", "start": 1716, "end": 1734, "loc": { "start": { "line": 59, "column": 15 }, "end": { "line": 59, "column": 33 }, "identifierName": "INITIALLY_DEFERRED" }, "name": "INITIALLY_DEFERRED" }, "arguments": [] } } ], "directives": [] }, "alternate": null } ], "directives": [] } }, { "type": "ExpressionStatement", "start": 1744, "end": 1788, "loc": { "start": { "line": 62, "column": 0 }, "end": { "line": 62, "column": 44 } }, "expression": { "type": "CallExpression", "start": 1744, "end": 1787, "loc": { "start": { "line": 62, "column": 0 }, "end": { "line": 62, "column": 43 } }, "callee": { "type": "MemberExpression", "start": 1744, "end": 1757, "loc": { "start": { "line": 62, "column": 0 }, "end": { "line": 62, "column": 13 } }, "object": { "type": "Identifier", "start": 1744, "end": 1748, "loc": { "start": { "line": 62, "column": 0 }, "end": { "line": 62, "column": 4 }, "identifierName": "util" }, "name": "util" }, "property": { "type": "Identifier", "start": 1749, "end": 1757, "loc": { "start": { "line": 62, "column": 5 }, "end": { "line": 62, "column": 13 }, "identifierName": "inherits" }, "name": "inherits" }, "computed": false }, "arguments": [ { "type": "Identifier", "start": 1758, "end": 1776, "loc": { "start": { "line": 62, "column": 14 }, "end": { "line": 62, "column": 32 }, "identifierName": "INITIALLY_DEFERRED" }, "name": "INITIALLY_DEFERRED" }, { "type": "Identifier", "start": 1778, "end": 1786, "loc": { "start": { "line": 62, "column": 34 }, "end": { "line": 62, "column": 42 }, "identifierName": "ABSTRACT" }, "name": "ABSTRACT" } ] } }, { "type": "ExpressionStatement", "start": 1790, "end": 1884, "loc": { "start": { "line": 64, "column": 0 }, "end": { "line": 66, "column": 2 } }, "expression": { "type": "AssignmentExpression", "start": 1790, "end": 1883, "loc": { "start": { "line": 64, "column": 0 }, "end": { "line": 66, "column": 1 } }, "operator": "=", "left": { "type": "MemberExpression", "start": 1790, "end": 1824, "loc": { "start": { "line": 64, "column": 0 }, "end": { "line": 64, "column": 34 } }, "object": { "type": "MemberExpression", "start": 1790, "end": 1818, "loc": { "start": { "line": 64, "column": 0 }, "end": { "line": 64, "column": 28 } }, "object": { "type": "Identifier", "start": 1790, "end": 1808, "loc": { "start": { "line": 64, "column": 0 }, "end": { "line": 64, "column": 18 }, "identifierName": "INITIALLY_DEFERRED" }, "name": "INITIALLY_DEFERRED" }, "property": { "type": "Identifier", "start": 1809, "end": 1818, "loc": { "start": { "line": 64, "column": 19 }, "end": { "line": 64, "column": 28 }, "identifierName": "prototype" }, "name": "prototype" }, "computed": false }, "property": { "type": "Identifier", "start": 1819, "end": 1824, "loc": { "start": { "line": 64, "column": 29 }, "end": { "line": 64, "column": 34 }, "identifierName": "toSql" }, "name": "toSql" }, "computed": false }, "right": { "type": "FunctionExpression", "start": 1827, "end": 1883, "loc": { "start": { "line": 64, "column": 37 }, "end": { "line": 66, "column": 1 } }, "id": { "type": "Identifier", "start": 1819, "end": 1824, "loc": { "start": { "line": 64, "column": 29 }, "end": { "line": 64, "column": 34 }, "identifierName": "toSql" }, "name": "toSql" }, "generator": false, "expression": false, "async": false, "params": [], "body": { "type": "BlockStatement", "start": 1838, "end": 1883, "loc": { "start": { "line": 64, "column": 48 }, "end": { "line": 66, "column": 1 } }, "body": [ { "type": "ReturnStatement", "start": 1842, "end": 1881, "loc": { "start": { "line": 65, "column": 2 }, "end": { "line": 65, "column": 41 } }, "argument": { "type": "StringLiteral", "start": 1849, "end": 1880, "loc": { "start": { "line": 65, "column": 9 }, "end": { "line": 65, "column": 40 } }, "extra": { "rawValue": "DEFERRABLE INITIALLY DEFERRED", "raw": "'DEFERRABLE INITIALLY DEFERRED'" }, "value": "DEFERRABLE INITIALLY DEFERRED" } } ], "directives": [] } } } }, { "type": "FunctionDeclaration", "start": 1886, "end": 2010, "loc": { "start": { "line": 68, "column": 0 }, "end": { "line": 72, "column": 1 } }, "id": { "type": "Identifier", "start": 1895, "end": 1914, "loc": { "start": { "line": 68, "column": 9 }, "end": { "line": 68, "column": 28 }, "identifierName": "INITIALLY_IMMEDIATE" }, "name": "INITIALLY_IMMEDIATE" }, "generator": false, "expression": false, "async": false, "params": [], "body": { "type": "BlockStatement", "start": 1917, "end": 2010, "loc": { "start": { "line": 68, "column": 31 }, "end": { "line": 72, "column": 1 } }, "body": [ { "type": "IfStatement", "start": 1921, "end": 2008, "loc": { "start": { "line": 69, "column": 2 }, "end": { "line": 71, "column": 3 } }, "test": { "type": "UnaryExpression", "start": 1925, "end": 1963, "loc": { "start": { "line": 69, "column": 6 }, "end": { "line": 69, "column": 44 } }, "operator": "!", "prefix": true, "argument": { "type": "BinaryExpression", "start": 1927, "end": 1962, "loc": { "start": { "line": 69, "column": 8 }, "end": { "line": 69, "column": 43 } }, "left": { "type": "ThisExpression", "start": 1927, "end": 1931, "loc": { "start": { "line": 69, "column": 8 }, "end": { "line": 69, "column": 12 } } }, "operator": "instanceof", "right": { "type": "Identifier", "start": 1943, "end": 1962, "loc": { "start": { "line": 69, "column": 24 }, "end": { "line": 69, "column": 43 }, "identifierName": "INITIALLY_IMMEDIATE" }, "name": "INITIALLY_IMMEDIATE" }, "extra": { "parenthesized": true, "parenStart": 1926 } }, "extra": { "parenthesizedArgument": false } }, "consequent": { "type": "BlockStatement", "start": 1965, "end": 2008, "loc": { "start": { "line": 69, "column": 46 }, "end": { "line": 71, "column": 3 } }, "body": [ { "type": "ReturnStatement", "start": 1971, "end": 2004, "loc": { "start": { "line": 70, "column": 4 }, "end": { "line": 70, "column": 37 } }, "argument": { "type": "NewExpression", "start": 1978, "end": 2003, "loc": { "start": { "line": 70, "column": 11 }, "end": { "line": 70, "column": 36 } }, "callee": { "type": "Identifier", "start": 1982, "end": 2001, "loc": { "start": { "line": 70, "column": 15 }, "end": { "line": 70,