sequelize
Version:
Multi dialect ORM for Node.JS/io.js
1,611 lines (1,610 loc) • 4.91 MB
JSON
{
"type": "File",
"start": 0,
"end": 26839,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 732,
"column": 0
}
},
"program": {
"type": "Program",
"start": 0,
"end": 26839,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 732,
"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"
},
{
"type": "VariableDeclaration",
"start": 158,
"end": 200,
"loc": {
"start": {
"line": 7,
"column": 0
},
"end": {
"line": 7,
"column": 42
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 164,
"end": 199,
"loc": {
"start": {
"line": 7,
"column": 6
},
"end": {
"line": 7,
"column": 41
}
},
"id": {
"type": "Identifier",
"start": 164,
"end": 173,
"loc": {
"start": {
"line": 7,
"column": 6
},
"end": {
"line": 7,
"column": 15
},
"identifierName": "BelongsTo"
},
"name": "BelongsTo"
},
"init": {
"type": "CallExpression",
"start": 176,
"end": 199,
"loc": {
"start": {
"line": 7,
"column": 18
},
"end": {
"line": 7,
"column": 41
}
},
"callee": {
"type": "Identifier",
"start": 176,
"end": 183,
"loc": {
"start": {
"line": 7,
"column": 18
},
"end": {
"line": 7,
"column": 25
},
"identifierName": "require"
},
"name": "require"
},
"arguments": [
{
"type": "StringLiteral",
"start": 184,
"end": 198,
"loc": {
"start": {
"line": 7,
"column": 26
},
"end": {
"line": 7,
"column": 40
}
},
"extra": {
"rawValue": "./belongs-to",
"raw": "'./belongs-to'"
},
"value": "./belongs-to"
}
]
}
}
],
"kind": "const"
},
{
"type": "VariableDeclaration",
"start": 201,
"end": 239,
"loc": {
"start": {
"line": 8,
"column": 0
},
"end": {
"line": 8,
"column": 38
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 207,
"end": 238,
"loc": {
"start": {
"line": 8,
"column": 6
},
"end": {
"line": 8,
"column": 37
}
},
"id": {
"type": "Identifier",
"start": 207,
"end": 214,
"loc": {
"start": {
"line": 8,
"column": 6
},
"end": {
"line": 8,
"column": 13
},
"identifierName": "HasMany"
},
"name": "HasMany"
},
"init": {
"type": "CallExpression",
"start": 217,
"end": 238,
"loc": {
"start": {
"line": 8,
"column": 16
},
"end": {
"line": 8,
"column": 37
}
},
"callee": {
"type": "Identifier",
"start": 217,
"end": 224,
"loc": {
"start": {
"line": 8,
"column": 16
},
"end": {
"line": 8,
"column": 23
},
"identifierName": "require"
},
"name": "require"
},
"arguments": [
{
"type": "StringLiteral",
"start": 225,
"end": 237,
"loc": {
"start": {
"line": 8,
"column": 24
},
"end": {
"line": 8,
"column": 36
}
},
"extra": {
"rawValue": "./has-many",
"raw": "'./has-many'"
},
"value": "./has-many"
}
]
}
}
],
"kind": "const"
},
{
"type": "VariableDeclaration",
"start": 240,
"end": 276,
"loc": {
"start": {
"line": 9,
"column": 0
},
"end": {
"line": 9,
"column": 36
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 246,
"end": 275,
"loc": {
"start": {
"line": 9,
"column": 6
},
"end": {
"line": 9,
"column": 35
}
},
"id": {
"type": "Identifier",
"start": 246,
"end": 252,
"loc": {
"start": {
"line": 9,
"column": 6
},
"end": {
"line": 9,
"column": 12
},
"identifierName": "HasOne"
},
"name": "HasOne"
},
"init": {
"type": "CallExpression",
"start": 255,
"end": 275,
"loc": {
"start": {
"line": 9,
"column": 15
},
"end": {
"line": 9,
"column": 35
}
},
"callee": {
"type": "Identifier",
"start": 255,
"end": 262,
"loc": {
"start": {
"line": 9,
"column": 15
},
"end": {
"line": 9,
"column": 22
},
"identifierName": "require"
},
"name": "require"
},
"arguments": [
{
"type": "StringLiteral",
"start": 263,
"end": 274,
"loc": {
"start": {
"line": 9,
"column": 23
},
"end": {
"line": 9,
"column": 34
}
},
"extra": {
"rawValue": "./has-one",
"raw": "'./has-one'"
},
"value": "./has-one"
}
]
}
}
],
"kind": "const"
},
{
"type": "VariableDeclaration",
"start": 277,
"end": 340,
"loc": {
"start": {
"line": 10,
"column": 0
},
"end": {
"line": 10,
"column": 63
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 283,
"end": 339,
"loc": {
"start": {
"line": 10,
"column": 6
},
"end": {
"line": 10,
"column": 62
}
},
"id": {
"type": "Identifier",
"start": 283,
"end": 299,
"loc": {
"start": {
"line": 10,
"column": 6
},
"end": {
"line": 10,
"column": 22
},
"identifierName": "AssociationError"
},
"name": "AssociationError"
},
"init": {
"type": "MemberExpression",
"start": 302,
"end": 339,
"loc": {
"start": {
"line": 10,
"column": 25
},
"end": {
"line": 10,
"column": 62
}
},
"object": {
"type": "CallExpression",
"start": 302,
"end": 322,
"loc": {
"start": {
"line": 10,
"column": 25
},
"end": {
"line": 10,
"column": 45
}
},
"callee": {
"type": "Identifier",
"start": 302,
"end": 309,
"loc": {
"start": {
"line": 10,
"column": 25
},
"end": {
"line": 10,
"column": 32
},
"identifierName": "require"
},
"name": "require"
},
"arguments": [
{
"type": "StringLiteral",
"start": 310,
"end": 321,
"loc": {
"start": {
"line": 10,
"column": 33
},
"end": {
"line": 10,
"column": 44
}
},
"extra": {
"rawValue": "../errors",
"raw": "'../errors'"
},
"value": "../errors"
}
]
},
"property": {
"type": "Identifier",
"start": 323,
"end": 339,
"loc": {
"start": {
"line": 10,
"column": 46
},
"end": {
"line": 10,
"column": 62
},
"identifierName": "AssociationError"
},
"name": "AssociationError"
},
"computed": false
}
}
],
"kind": "const",
"trailingComments": [
{
"type": "CommentBlock",
"value": "*\n * Many-to-many association with a join table.\n *\n * When the join table has additional attributes, these can be passed in the options object:\n *\n * ```js\n * UserProject = sequelize.define('user_project', {\n * role: Sequelize.STRING\n * });\n * User.belongsToMany(Project, { through: UserProject });\n * Project.belongsToMany(User, { through: UserProject });\n * // through is required!\n *\n * user.addProject(project, { through: { role: 'manager' }});\n * ```\n *\n * All methods allow you to pass either a persisted instance, its primary key, or a mixture:\n *\n * ```js\n * Project.create({ id: 11 }).then(function (project) {\n * user.addProjects([project, 12]);\n * });\n * ```\n *\n * If you want to set several target instances, but with different attributes you have to set the attributes on the instance, using a property with the name of the through model:\n *\n * ```js\n * p1.UserProjects = {\n * started: true\n * }\n * user.setProjects([p1, p2], { through: { started: false }}) // The default value is false, but p1 overrides that.\n * ```\n *\n * Similarly, when fetching through a join table with custom attributes, these attributes will be available as an object with the name of the through model.\n * ```js\n * user.getProjects().then(function (projects) {\n * let p1 = projects[0]\n * p1.UserProjects.started // Is this project started yet?\n * })\n * ```\n *\n * In the API reference below, add the name of the association to the method, e.g. for `User.belongsToMany(Project)` the getter will be `user.getProjects()`.\n *\n * @see {@link Model.belongsToMany}\n ",
"start": 342,
"end": 1910,
"loc": {
"start": {
"line": 12,
"column": 0
},
"end": {
"line": 56,
"column": 3
}
}
}
]
},
{
"type": "ClassDeclaration",
"start": 1911,
"end": 26719,
"loc": {
"start": {
"line": 57,
"column": 0
},
"end": {
"line": 727,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 1917,
"end": 1930,
"loc": {
"start": {
"line": 57,
"column": 6
},
"end": {
"line": 57,
"column": 19
},
"identifierName": "BelongsToMany"
},
"name": "BelongsToMany",
"leadingComments": null
},
"superClass": {
"type": "Identifier",
"start": 1939,
"end": 1950,
"loc": {
"start": {
"line": 57,
"column": 28
},
"end": {
"line": 57,
"column": 39
},
"identifierName": "Association"
},
"name": "Association"
},
"body": {
"type": "ClassBody",
"start": 1951,
"end": 26719,
"loc": {
"start": {
"line": 57,
"column": 40
},
"end": {
"line": 727,
"column": 1
}
},
"body": [
{
"type": "ClassMethod",
"start": 1955,
"end": 7584,
"loc": {
"start": {
"line": 58,
"column": 2
},
"end": {
"line": 224,
"column": 3
}
},
"computed": false,
"key": {
"type": "Identifier",
"start": 1955,
"end": 1966,
"loc": {
"start": {
"line": 58,
"column": 2
},
"end": {
"line": 58,
"column": 13
},
"identifierName": "constructor"
},
"name": "constructor"
},
"static": false,
"kind": "constructor",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [
{
"type": "Identifier",
"start": 1967,
"end": 1973,
"loc": {
"start": {
"line": 58,
"column": 14
},
"end": {
"line": 58,
"column": 20
},
"identifierName": "source"
},
"name": "source"
},
{
"type": "Identifier",
"start": 1975,
"end": 1981,
"loc": {
"start": {
"line": 58,
"column": 22
},
"end": {
"line": 58,
"column": 28
},
"identifierName": "target"
},
"name": "target"
},
{
"type": "Identifier",
"start": 1983,
"end": 1990,
"loc": {
"start": {
"line": 58,
"column": 30
},
"end": {
"line": 58,
"column": 37
},
"identifierName": "options"
},
"name": "options"
}
],
"body": {
"type": "BlockStatement",
"start": 1992,
"end": 7584,
"loc": {
"start": {
"line": 58,
"column": 39
},
"end": {
"line": 224,
"column": 3
}
},
"body": [
{
"type": "ExpressionStatement",
"start": 1998,
"end": 2029,
"loc": {
"start": {
"line": 59,
"column": 4
},
"end": {
"line": 59,
"column": 35
}
},
"expression": {
"type": "CallExpression",
"start": 1998,
"end": 2028,
"loc": {
"start": {
"line": 59,
"column": 4
},
"end": {
"line": 59,
"column": 34
}
},
"callee": {
"type": "Super",
"start": 1998,
"end": 2003,
"loc": {
"start": {
"line": 59,
"column": 4
},
"end": {
"line": 59,
"column": 9
}
}
},
"arguments": [
{
"type": "Identifier",
"start": 2004,
"end": 2010,
"loc": {
"start": {
"line": 59,
"column": 10
},
"end": {
"line": 59,
"column": 16
},
"identifierName": "source"
},
"name": "source"
},
{
"type": "Identifier",
"start": 2012,
"end": 2018,
"loc": {
"start": {
"line": 59,
"column": 18
},
"end": {
"line": 59,
"column": 24
},
"identifierName": "target"
},
"name": "target"
},
{
"type": "Identifier",
"start": 2020,
"end": 2027,
"loc": {
"start": {
"line": 59,
"column": 26
},
"end": {
"line": 59,
"column": 33
},
"identifierName": "options"
},
"name": "options"
}
]
}
},
{
"type": "IfStatement",
"start": 2035,
"end": 2258,
"loc": {
"start": {
"line": 61,
"column": 4
},
"end": {
"line": 63,
"column": 5
}
},
"test": {
"type": "LogicalExpression",
"start": 2039,
"end": 2139,
"loc": {
"start": {
"line": 61,
"column": 8
},
"end": {
"line": 61,
"column": 108
}
},
"left": {
"type": "LogicalExpression",
"start": 2039,
"end": 2106,
"loc": {
"start": {
"line": 61,
"column": 8
},
"end": {
"line": 61,
"column": 75
}
},
"left": {
"type": "BinaryExpression",
"start": 2039,
"end": 2073,
"loc": {
"start": {
"line": 61,
"column": 8
},
"end": {
"line": 61,
"column": 42
}
},
"left": {
"type": "MemberExpression",
"start": 2039,
"end": 2059,
"loc": {
"start": {
"line": 61,
"column": 8
},
"end": {
"line": 61,
"column": 28
}
},
"object": {
"type": "MemberExpression",
"start": 2039,
"end": 2051,
"loc": {
"start": {
"line": 61,
"column": 8
},
"end": {
"line": 61,
"column": 20
}
},
"object": {
"type": "ThisExpression",
"start": 2039,
"end": 2043,
"loc": {
"start": {
"line": 61,
"column": 8
},
"end": {
"line": 61,
"column": 12
}
}
},
"property": {
"type": "Identifier",
"start": 2044,
"end": 2051,
"loc": {
"start": {
"line": 61,
"column": 13
},
"end": {
"line": 61,
"column": 20
},
"identifierName": "options"
},
"name": "options"
},
"computed": false
},
"property": {
"type": "Identifier",
"start": 2052,
"end": 2059,
"loc": {
"start": {
"line": 61,
"column": 21
},
"end": {
"line": 61,
"column": 28
},
"identifierName": "through"
},
"name": "through"
},
"computed": false
},
"operator": "===",
"right": {
"type": "Identifier",
"start": 2064,
"end": 2073,
"loc": {
"start": {
"line": 61,
"column": 33
},
"end": {
"line": 61,
"column": 42
},
"identifierName": "undefined"
},
"name": "undefined"
}
},
"operator": "||",
"right": {
"type": "BinaryExpression",
"start": 2077,
"end": 2106,
"loc": {
"start": {
"line": 61,
"column": 46
},
"end": {
"line": 61,
"column": 75
}
},
"left": {
"type": "MemberExpression",
"start": 2077,
"end": 2097,
"loc": {
"start": {
"line": 61,
"column": 46
},
"end": {
"line": 61,
"column": 66
}
},
"object": {
"type": "MemberExpression",
"start": 2077,
"end": 2089,
"loc": {
"start": {
"line": 61,
"column": 46
},
"end": {
"line": 61,
"column": 58
}
},
"object": {
"type": "ThisExpression",
"start": 2077,
"end": 2081,
"loc": {
"start": {
"line": 61,
"column": 46
},
"end": {
"line": 61,
"column": 50
}
}
},
"property": {
"type": "Identifier",
"start": 2082,
"end": 2089,
"loc": {
"start": {
"line": 61,
"column": 51
},
"end": {
"line": 61,
"column": 58
},
"identifierName": "options"
},
"name": "options"
},
"computed": false
},
"property": {
"type": "Identifier",
"start": 2090,
"end": 2097,
"loc": {
"start": {
"line": 61,
"column": 59
},
"end": {
"line": 61,
"column": 66
},
"identifierName": "through"
},
"name": "through"
},
"computed": false
},
"operator": "===",
"right": {
"type": "BooleanLiteral",
"start": 2102,
"end": 2106,
"loc": {
"start": {
"line": 61,
"column": 71
},
"end": {
"line": 61,
"column": 75
}
},
"value": true
}
}
},
"operator": "||",
"right": {
"type": "BinaryExpression",
"start": 2110,
"end": 2139,
"loc": {
"start": {
"line": 61,
"column": 79
},
"end": {
"line": 61,
"column": 108
}
},
"left": {
"type": "MemberExpression",
"start": 2110,
"end": 2130,
"loc": {
"start": {
"line": 61,
"column": 79
},
"end": {
"line": 61,
"column": 99
}
},
"object": {
"type": "MemberExpression",
"start": 2110,
"end": 2122,
"loc": {
"start": {
"line": 61,
"column": 79
},
"end": {
"line": 61,
"column": 91
}
},
"object": {
"type": "ThisExpression",
"start": 2110,
"end": 2114,
"loc": {
"start": {
"line": 61,
"column": 79
},
"end": {
"line": 61,
"column": 83
}
}
},
"property": {
"type": "Identifier",
"start": 2115,
"end": 2122,
"loc": {
"start": {
"line": 61,
"column": 84
},
"end": {
"line": 61,
"column": 91
},
"identifierName": "options"
},
"name": "options"
},
"computed": false
},
"property": {
"type": "Identifier",
"start": 2123,
"end": 2130,
"loc": {
"start": {
"line": 61,
"column": 92
},
"end": {
"line": 61,
"column": 99
},
"identifierName": "through"
},
"name": "through"
},
"computed": false
},
"operator": "===",
"right": {
"type": "NullLiteral",
"start": 2135,
"end": 2139,
"loc": {
"start": {
"line": 61,
"column": 104
},
"end": {
"line": 61,
"column": 108
}
}
}
}
},
"consequent": {
"type": "BlockStatement",
"start": 2141,
"end": 2258,
"loc": {
"start": {
"line": 61,
"column": 110
},
"end": {
"line": 63,
"column": 5
}
},
"body": [
{
"type": "ThrowStatement",
"start": 2149,
"end": 2252,
"loc": {
"start": {
"line": 62,
"column": 6
},
"end": {
"line": 62,
"column": 109
}
},
"argument": {
"type": "NewExpression",
"start": 2155,
"end": 2251,
"loc": {
"start": {
"line": 62,
"column": 12
},
"end": {
"line": 62,
"column": 108
}
},
"callee": {