├── .DS_Store ├── .gitignore ├── LICENSE ├── README.md ├── docs ├── .DS_Store ├── association-types.md ├── column-types.md ├── css │ └── extra.css ├── eager-loading.md ├── getters-and-setters.md ├── getting-started.md ├── hooks.md ├── index.md ├── inserting-updating-destroying.md ├── instance-and-class-methods.md ├── many-many-associations.md ├── model-definition.md ├── one-many-associations.md ├── one-one-relations.md ├── querying.md ├── search-operators.md ├── validators-and-default-values.md └── virtual-columns.md ├── mkdocs.yml ├── requirements.txt └── runtime.txt /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FullstackAcademy/SequelizeGuides/d6abfafaa4bd5a238308e5a00cee3d118e90ce9f/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | 49 | # Translations 50 | *.mo 51 | *.pot 52 | 53 | # Django stuff: 54 | *.log 55 | local_settings.py 56 | 57 | # Flask stuff: 58 | instance/ 59 | .webassets-cache 60 | 61 | # Scrapy stuff: 62 | .scrapy 63 | 64 | # Sphinx documentation 65 | docs/_build/ 66 | 67 | # PyBuilder 68 | target/ 69 | 70 | # Jupyter Notebook 71 | .ipynb_checkpoints 72 | 73 | # pyenv 74 | .python-version 75 | 76 | # celery beat schedule file 77 | celerybeat-schedule 78 | 79 | # SageMath parsed files 80 | *.sage.py 81 | 82 | # dotenv 83 | .env 84 | 85 | # virtualenv 86 | .venv 87 | venv/ 88 | ENV/ 89 | 90 | # Spyder project settings 91 | .spyderproject 92 | .spyproject 93 | 94 | # Rope project settings 95 | .ropeproject 96 | 97 | # mkdocs documentation 98 | /site 99 | 100 | # mypy 101 | .mypy_cache/ 102 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Fullstack Academy 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SequelizeGuides 2 | 3 | Unofficial guides to Sequelize, meant as a supplement to the official documentation. 4 | 5 | # Contribuitions 6 | Contributions are welcomed (examples must include Pugs, though). 7 | -------------------------------------------------------------------------------- /docs/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FullstackAcademy/SequelizeGuides/d6abfafaa4bd5a238308e5a00cee3d118e90ce9f/docs/.DS_Store -------------------------------------------------------------------------------- /docs/association-types.md: -------------------------------------------------------------------------------- 1 | [Official Docs](http://docs.sequelizejs.com/manual/tutorial/associations.html) 2 | 3 | Associations in Sequelize establish three things: 4 | 5 | 1. For one-one or one-many associations, it establishes a foreign key relationship between two tables (though a table could be related to itself). For many-many associations, it establishes a join-table that contains pairs of foreign keys. 6 | 2. It creates several special instance methods (like "getAssociation", "setAssociation", and potentially others depending on the type of association) that an instance can use to search for the instances that they are related to 7 | 3. It creates the ability to use "include" in queries to include data about related rows (known as "eager loading") 8 | 9 | ## Types of Associations 10 | 11 | It is possible to specify the following associations in Sequelize: 12 | 13 | * `belongsTo` 14 | * `hasOne` 15 | * `hasMany` 16 | * `belongsToMany` 17 | 18 | These relations can be combined to establish *one-one*, *one-many* and *many-many* relationships, like so: 19 | 20 | * `one-one` 21 | * `A.belongsTo(B)` 22 | * `B.hasOne(A)` 23 | 24 | * `one-many` 25 | * `A.belongsTo(B)` 26 | * `B.hasMany(A)` 27 | 28 | * `many-many` 29 | * `A.belongsToMany(B, {through: 'AB'})` 30 | * `B.belongsToMany(A, {through: 'AB'})` 31 | -------------------------------------------------------------------------------- /docs/column-types.md: -------------------------------------------------------------------------------- 1 | [Official Docs](http://docs.sequelizejs.com/manual/tutorial/models-definition.html#data-types) 2 | 3 | The example below demonstrates some common data types: 4 | 5 | ```javascript 6 | const Pug = db.define('pugs', { 7 | name: { 8 | type: Sequelize.STRING // for shorter strings (< 256 chars) 9 | }, 10 | bio: { 11 | type: Sequelize.TEXT // for longer strings 12 | }, 13 | age: { 14 | type: Sequelize.INTEGER 15 | }, 16 | birthday: { 17 | type: Sequelize.DATE 18 | }, 19 | colors: { 20 | type: Sequelize.ENUM('black', 'fawn') 21 | }, 22 | toys: { 23 | type: Sequelize.ARRAY(Sequelize.TEXT) // an array of text strings (Postgres only) 24 | }, 25 | adoptedStatus: { 26 | type: Sequelize.BOOLEAN 27 | } 28 | }) 29 | ``` 30 | -------------------------------------------------------------------------------- /docs/css/extra.css: -------------------------------------------------------------------------------- 1 | footer { 2 | font-size: 10px; 3 | } 4 | 5 | .rst-footer-buttons { 6 | font-size: 16px; 7 | } -------------------------------------------------------------------------------- /docs/eager-loading.md: -------------------------------------------------------------------------------- 1 | # Joins/Includes (aka "Eager Loading") 2 | [Official Docs](http://docs.sequelizejs.com/manual/tutorial/models-usage.html#eager-loading) 3 | 4 | If we have two tables that are associated with each other, we often want to join that data together. In raw SQL queries, our favorite tool for this is an INNER JOIN. We can do something similar in Sequelize - it just goes by the slightly different name of "eager loading". Don't get hung up on the terminology - when you see "eager loading", think "join two tables". 5 | 6 | If two tables have an association, we can "include" information from the associated table like so: 7 | 8 | ```js 9 | const Pug = db.define('pugs', {name: Sequelize.STRING}) 10 | const Owner = db.define('owners', {name: Sequelize.STRING}) 11 | 12 | Pug.belongsTo(Owner) 13 | 14 | const getPugs = async () => { 15 | const pugs = await Pug.findAll({ // we want to find all the pugs, and include their owners 16 | include: [{model: Owner}] 17 | }) 18 | 19 | console.log(pugs) 20 | // [{name: 'Cody', ownerId: 1, owner: {name: 'Tom'}}, ...etc] 21 | } 22 | ``` 23 | 24 | *Important!* A Model can only eagerly load an association if the association is defined *on* that model. 25 | 26 | This means that for the above example, if we attempt to do the following: 27 | 28 | ```js 29 | const Pug = db.define('pugs', {name: Sequelize.STRING}) 30 | const Owner = db.define('owners', {name: Sequelize.STRING}) 31 | 32 | // the relation only exists on Pug 33 | Pug.belongsTo(Owner) 34 | 35 | Owner.findAll({include: [{model: Pug}]}) // this will error! 36 | ``` 37 | 38 | ...it will error! For us to include Pug when we query Owner, we must also establish the 'hasOne' or 'hasMany' association between Owners and Pugs. 39 | 40 | Example with `hasOne`: 41 | 42 | ```javascript 43 | const Pug = db.define('pugs', {name: Sequelize.STRING}) 44 | const Owner = db.define('owners', {name: Sequelize.STRING}) 45 | 46 | Pug.belongsTo(Owner) 47 | Owner.hasOne(Pug) // 1-1 association 48 | 49 | const getPugs = async () => { 50 | const owners = await Owner.findAll({include: [{model: Pug}]}) 51 | console.log(owners) // [{name: 'Tom', pug: {name: 'Cody', ownerId: 1}}] 52 | } 53 | ``` 54 | 55 | Example with `hasMany`: 56 | 57 | ```javascript 58 | const Pug = db.define('pugs', {name: Sequelize.STRING}) 59 | const Owner = db.define('owners', {name: Sequelize.STRING}) 60 | 61 | Pug.belongsTo(Owner) 62 | Owner.hasMany(Pug) // 1-Many Relationship 63 | 64 | const getPugs = async () => { 65 | const owners = await Owner.findAll({include: [{model: Pug}]}) 66 | console.log(owners) // [{name: 'Tom', pugs: [{name: 'Cody', ownerId: 1}]}] 67 | } 68 | ``` 69 | 70 | Note that the difference between the two examples above is that in the `hasOne` case, the resultant owners have a "pug" field with the name of their (single) pug. In the `hasMany` case, the resultant owners have a "pugs" (plural!) field with an _array_ of their (possibly many) pugs! 71 | 72 | This same rule applies to many-to-many associations! 73 | -------------------------------------------------------------------------------- /docs/getters-and-setters.md: -------------------------------------------------------------------------------- 1 | [Official Docs](http://docs.sequelizejs.com/manual/tutorial/models-definition.html#getters-setters) 2 | 3 | Getters and setters are ways of customizing what happens when someone 'gets' or 'sets' a property on an instance. 'Get' and 'set' are referred to as "meta-operations" in JavaScript. 4 | 5 | ```javascript 6 | const someObj = {foo: 'bar'} 7 | someObj.foo // the 'get' meta-operation 8 | someObj.foo = 'baz' // the 'set' meta-operation 9 | ``` 10 | 11 | Normally, we expect that 'getting' a property will simply return the value at that key in the object, and 'setting' a property will set that property in the object. 12 | 13 | 'Getters' and 'setters' allow us to *override* that expected behavior. 14 | 15 | ## Definition 16 | 17 | ```javascript 18 | const Pug = db.define('pugs', { 19 | name: { 20 | type: Sequelize.STRING, 21 | get () { // this defines the 'getter' 22 | // 'this' refers to the instance (same as an instance method) 23 | // in a 'getter', you should not refer to the names of the columns directly 24 | // as this will recursively call the getter and result in a stack overflow, 25 | // instead, use the `this.getDataValue` method 26 | return this.getDataValue('name') + ' the pug' 27 | // this getter will automatically append ' the pug' to any name 28 | }, 29 | set (valueToBeSet) { // defines the 'setter' 30 | // 'this' refers to the instance (same as above) 31 | // use `this.setDataValue` to actually set the value 32 | this.setDataValue('name', valueToBeSet.toUpperCase()) 33 | // this setter will automatically set the 'name' property to be uppercased 34 | } 35 | } 36 | }) 37 | ``` 38 | 39 | ## Usage 40 | 41 | ```javascript 42 | // building or creating an instance will trigger the 'set' operation, causing the name to be capitalized 43 | const createdPug = await Pug.create({name: 'cody'}) 44 | 45 | // when we 'get' createdPug.name, we get the capitalized 'CODY' + ' the pug' from our getter 46 | console.log(createdPug.name) // CODY the pug 47 | 48 | // this is the 'set' operation, which will capitalize the name we set 49 | createdPug.name = 'murphy' 50 | console.log(createdPug.name) // MURPHY the pug 51 | 52 | ``` 53 | -------------------------------------------------------------------------------- /docs/getting-started.md: -------------------------------------------------------------------------------- 1 | # Installation 2 | 3 | Sequelize is available via NPM. 4 | 5 | ```bash 6 | $ npm install sequelize 7 | 8 | # And the following: 9 | $ npm install pg 10 | ``` 11 | 12 | # Setting up a connection 13 | 14 | Sequelize allow you to use a connection uri: 15 | 16 | ```js 17 | const Sequelize = require('sequelize') 18 | const db = new Sequelize('postgres://localhost:5432/your-db') 19 | ``` 20 | 21 | # Your first model 22 | 23 | Models are defined with the `.define()` method: `db.define('name', {attributes}, {options})`. 24 | 25 | ```js 26 | const User = db.define('user', { 27 | firstName: { 28 | type: Sequelize.STRING 29 | }, 30 | lastName: { 31 | type: Sequelize.STRING 32 | } 33 | }); 34 | 35 | // force: true will drop the table if it already exists 36 | await User.sync({force: true}) 37 | // Table created 38 | 39 | await User.create({ 40 | firstName: 'John', 41 | lastName: 'Hancock' 42 | }) 43 | 44 | 45 | ``` 46 | 47 | You can read more about creating models and available types at [Column Types](/column-types) 48 | 49 | # Your first query 50 | 51 | ```js 52 | const users = await User.findAll(); 53 | 54 | console.log(users); 55 | ``` 56 | 57 | 58 | 59 | ### Instances vs data 60 | 61 | When you console log the returned value from a Sequelize statement (just like in the example above), what you see is a weird looking object like this: 62 | 63 | ```js 64 | { 65 | dataValues: 66 | { id: 16, 67 | firstName: 'John', 68 | lastName: 'Hancock', 69 | createdAt: 2018-01-22T19:18:39.875Z, 70 | updatedAt: 2018-01-22T19:18:39.879Z, 71 | authorId: 6 }, 72 | _changed: {}, 73 | _modelOptions: 74 | { ... }, // Omitted for brevity 75 | _options: 76 | { ... }, // Omitted for brevity 77 | __eagerlyLoadedAssociations: [], 78 | isNewRecord: false } 79 | 80 | ``` 81 | 82 | This is not a simple object containing only data, this is a full instance of the given model: It contains the data you queried plus a bunch of additional information and methods. 83 | 84 | Notice that the actual data is available inside `dataValues`, but don't worry about this key - Sequelize creates getters and setters automatically for you - In plain english this means that you can simply type the desired field name directly: 85 | 86 | ```js 87 | user.firstName // 'John' 88 | ``` 89 | 90 | 91 | ## Promises 92 | 93 | Sequelize uses promises to control async control-flow. 94 | 95 | **Note:** _Internally, Sequelize uses an independent copy of [Bluebird](http://bluebirdjs.com). You can access it using 96 | `Sequelize.Promise` if you want to set any Bluebird-specific options_. 97 | 98 | 99 | Basically, a promise represents a value which will be present at some point - "I promise you I will give you a result or an error at some point". This means that 100 | 101 | ```js 102 | // DON'T DO THIS 103 | user = User.findOne() 104 | 105 | console.log(user.get('firstName')); 106 | ``` 107 | 108 | _will never work!_ This is because `user` is a promise object, not a data row from the DB. The right way to do it is: 109 | 110 | ```js 111 | user = await User.findOne() 112 | 113 | console.log(user.get('firstName')); 114 | ``` 115 | 116 | **Note:** this will work but only in the body of an [async](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function) function: 117 | 118 | -------------------------------------------------------------------------------- /docs/hooks.md: -------------------------------------------------------------------------------- 1 | [Official Docs](http://docs.sequelizejs.com/manual/tutorial/hooks.html) 2 | 3 | When we perform various operations in sequelize (like updating, creating, or destroying an instance), that's not _all_ that happens. There are various stages that an instance goes through as it's being updated/created/destroyed. These are called *lifecycle events*. Hooks give us the ability to "hook" into these lifecycle events and execute arbitrary functions related to that instance. 4 | 5 | This can be useful in several ways. For example: 6 | 7 | * Before creating an instance of a User, we could hash that user's plaintext password, so that what gets saved is the hashed version 8 | * Before destroying an instance of a TodoList, we could also destroy all Todos that are associated with that TodoList. 9 | 10 | We define hooks on the model, but they are executed against instances when those instances pass through those lifecycle events. 11 | 12 | All hooks are defined using a function that takes two arguments. The first argument is the instance passing through the lifecycle hook. The second argument is an options object (rarely used - you can often ignore it or exclude it). 13 | 14 | Here's what the above two examples might look like. Note that there are several different ways that hooks can be defined (but they are mostly equivalent). 15 | 16 | ```javascript 17 | // given the following User model: 18 | const User = db.define('users', { 19 | name: Sequelize.STRING, 20 | password: Sequelize.STRING 21 | }) 22 | // we want to hook into the "beforeCreate" lifecycle event 23 | // this lifecycle event happens before an instance is created and saved to the database, 24 | // so we can use this to change something about the instance before it gets saved. 25 | 26 | User.beforeCreate((userInstance, optionsObject) => { 27 | userInstance.password = hash(userInstance.password) 28 | }) 29 | 30 | // This lifecycle hook would get called after calling something like: 31 | // User.create({name: 'Cody', password: '123'}) 32 | // and it would run before the new user is saved in the database. 33 | // If we were to inspect the newly created user, we would see that 34 | // the user.password wouldn't be '123', but it would be another string 35 | // representing the hashed '123' 36 | ``` 37 | 38 | ```javascript 39 | // given the following TodoList and Todo models: 40 | const TodoList = db.define('todolists', { 41 | name: Sequelize.STRING 42 | }) 43 | 44 | const Todo = db.define('todo', { 45 | name: Sequelize.STRING, 46 | completedStatus: Sequelize.BOOLEAN 47 | }) 48 | 49 | Todo.belongsTo(TodoList, {as: 'list'}) 50 | 51 | // we want to hook into the "beforeDestroy" lifecycle event 52 | // this lifecycle event happens before an instance is removed from the database, 53 | // so we can use this to "clean up" other rows that are also no longer needed 54 | TodoList.beforeDestroy((todoListInstance) => { 55 | // make sure to return any promises inside hooks! This way Sequelize will be sure to 56 | // wait for the promise to resolve before advancing to the next lifecycle stage! 57 | return Todo.destroy({ 58 | where: { 59 | listId: todoListInstance.id 60 | } 61 | }) 62 | }) 63 | ``` 64 | 65 | 66 | ## Available Hooks (in Order of Operation) 67 | 68 | ``` 69 | (1) 70 | beforeBulkCreate(instances, options) 71 | beforeBulkDestroy(options) 72 | beforeBulkUpdate(options) 73 | (2) 74 | beforeValidate(instance, options) 75 | (-) 76 | validate 77 | (3) 78 | afterValidate(instance, options) 79 | - or - 80 | validationFailed(instance, options, error) 81 | (4) 82 | beforeCreate(instance, options) 83 | beforeDestroy(instance, options) 84 | beforeUpdate(instance, options) 85 | beforeSave(instance, options) 86 | beforeUpsert(values, options) 87 | (-) 88 | create 89 | destroy 90 | update 91 | (5) 92 | afterCreate(instance, options) 93 | afterDestroy(instance, options) 94 | afterUpdate(instance, options) 95 | afterSave(instance, options) 96 | afterUpsert(created, options) 97 | (6) 98 | afterBulkCreate(instances, options) 99 | afterBulkDestroy(options) 100 | afterBulkUpdate(options) 101 | ``` -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | ![Sequelize](http://docs.sequelizejs.com/manual/asset/logo-small.png) 2 | 3 | A Sequelize reference as a supplement to the official documentation. 4 | 5 | 6 | ## Authors 7 | Tom Kelly (@tmkelly28), FullStack Academy of Code & contributors. -------------------------------------------------------------------------------- /docs/inserting-updating-destroying.md: -------------------------------------------------------------------------------- 1 | # Model.findOrCreate 2 | [Official Docs](http://docs.sequelizejs.com/manual/tutorial/models-usage.html#-findorcreate-search-for-a-specific-element-or-create-it-if-not-available) 3 | 4 | Finds an instance that matches the specified query. If no such instance exists, it will create one. This method is a little funny - it returns a promise for an array! The first element of the array is the instance. The second element is a boolean (true or false), which will be true if the instance was newly created, and false if it wasn't (that is, an existing match was found). 5 | 6 | In the example below, assume we do not have any existing row in our pugs table with the name 'Cody'. 7 | 8 | ```javascript 9 | 10 | const arr = await Pug.findOrCreate({where: {name: 'Cody'}}) 11 | const instance = arr[0] // the first element is the instance 12 | const wasCreated = arr[1] // the second element tells us if the instance was newly created 13 | console.log(instance) // {id: 1, name: 'Cody', etc...} 14 | console.log(wasCreated) // true 15 | 16 | 17 | // now if we findOrCreate a second time... 18 | 19 | const arr2 = Pug.findOrCreate({where: {name: 'Cody'}}) 20 | const instance = arr2[0] 21 | const wasCreated = arr2[1] 22 | console.log(instance) // {id: 1, name: 'Cody', etc...} 23 | console.log(wasCreated) // false -> the query found an existing pug that matched the query 24 | ``` 25 | 26 | It's often preferably to handle with a promise for an array using destructuring assignment: 27 | 28 | ```javascript 29 | const [instance, wasCreated] = await Pug.findOrCreate({where: {name: 'Cody'}}) 30 | ``` 31 | 32 | For other examples of this pattern: http://es6-features.org/#ParameterContextMatching 33 | 34 | # new Model() 35 | 36 | Creates a temporary instance. Returns the instance. This instance is NOT yet saved to the database! 37 | 38 | ```javascript 39 | const cody = new Pug({name: 'Cody'}) 40 | console.log(cody) // we can start using cody right away...but cody is NOT in our db yet 41 | ``` 42 | 43 | **Note:** This operation is synchronous - you should not use the `await` keyword. 44 | 45 | 46 | ## Model.build 47 | 48 | Same as above (with alternative syntax) - creates a temporary, unsaved instance. 49 | 50 | ```javascript 51 | const cody = Pug.build({name: 'Cody'}) 52 | console.log(cody) // we can start using cody right away...but cody is NOT in our db yet 53 | ``` 54 | 55 | **Note:** This operation is synchronous - you should not use the `await` keyword. 56 | 57 | 58 | # Model.create 59 | 60 | Creates and saves a new row to the database. Returns a promise for the created instance. 61 | 62 | ```javascript 63 | const cody = await Pug.create({name: 'Cody'}) 64 | 65 | // now, cody is saved in our database 66 | console.log(cody) 67 | ``` 68 | 69 | # Model.update 70 | 71 | Updates all instances that match a query. 72 | Takes two parameters: the first parameter contains the info you want to update. The second parameter contains the query for which instances to update. 73 | 74 | Like `findOrCreate`, it returns a promise for an array. The first element of the array is the number of rows that were affected. The second element of the array is the affected rows themselves. 75 | 76 | ```javascript 77 | // update all pugs whose age is 7 to have an adoptedStatus of true 78 | // because we return a promise for an array, destructuring is recommended 79 | const [numberOfAffectedRows, affectedRows] = await Pug.update({ 80 | adoptedStatus: true 81 | }, { 82 | where: {age: 7}, 83 | returning: true, // needed for affectedRows to be populated 84 | plain: true // makes sure that the returned instances are just plain objects 85 | }) 86 | 87 | console.log(numberOfAffectedRows) // say we had 3 pugs with the age of 7. This will then be 3 88 | console.log(affectedRows) // this will be an array of the three affected pugs 89 | 90 | ``` 91 | 92 | # Model.destroy 93 | 94 | Destroys all instances that match a query. 95 | It returns a promise for the number of rows that were deleted. 96 | 97 | ```javascript 98 | const numAffectedRows = await Pug.destroy({ 99 | where: { 100 | age: 7 // deletes all pugs whose age is 7 101 | } 102 | }) 103 | 104 | console.log(numAffectedRows) // if we had 3 pugs with the age of 7, this will be 3 105 | 106 | ``` 107 | 108 | --- 109 | 110 | # Using Instances 111 | 112 | ## instance.save and instance.update 113 | [Official Docs](http://docs.sequelizejs.com/manual/tutorial/instances.html#updating-saving-persisting-an-instance) 114 | 115 | If we already have an instance, we can save changes with either instance.save or instance.update 116 | 117 | Both returns promises for the saved/updated instance 118 | 119 | Here's an example using save: 120 | ```javascript 121 | // we already have a pug instance, which we've put in a variable called cody 122 | console.log(cody.age) // 7 123 | cody.age = 8 // we can change the age to 8 (but it isn't saved in the database yet) 124 | cody = await cody.save() // we can use .save to actually save to the database 125 | 126 | console.log(cody.age) // 8 127 | ``` 128 | 129 | Here's another example using update: 130 | ```javascript 131 | console.log(cody.age) // 7 132 | cody = await cody.update({age: 8}) 133 | 134 | console.log(cody.age) // 8 135 | ``` 136 | 137 | ## instance.destroy 138 | [Official Docs](http://docs.sequelizejs.com/manual/tutorial/instances.html#destroying-deleting-persistent-instances) 139 | 140 | If we want to remove an individual instance from the database, we can use instance.destroy. 141 | It returns a promise that will be resolved when the row is removed from the database. 142 | (The promise itself does not resolve to anything in particular though - it's always just an empty array) 143 | 144 | ```javascript 145 | // no need to expect the promise to resolve to any useful value 146 | await cody.destroy() // no! bye Cody! 147 | 148 | // now the cody row is no longer in the database 149 | ``` 150 | 151 | -------------------------------------------------------------------------------- /docs/instance-and-class-methods.md: -------------------------------------------------------------------------------- 1 | Instance and class methods are common ways to add functionality to your Sequelize.js models. 2 | 3 | # Instance Methods 4 | 5 | The code example below demonstrates an instance method. 6 | Instance methods are methods that are available on *instances* of the model. 7 | We often write these to get information or do something related *to that instance*. 8 | 9 | ## Definition: 10 | ```javascript 11 | const Pug = db.define('pugs', {/* etc*/}) 12 | 13 | // instance methods are defined on the model's .prototype 14 | Pug.prototype.celebrateBirthday = function () { 15 | // 'this' in an instance method refers to the instance itself 16 | const birthday = new Date(this.birthday) 17 | const today = new Date() 18 | if (birthday.getMonth() === today.getMonth() && today.getDate() === birthday.getDate()) { 19 | console.log('Happy birthday!') 20 | } 21 | } 22 | ``` 23 | 24 | ## Usage: 25 | 26 | ```js 27 | const createdPug = await Pug.create({name: 'Cody'}) // let's say `birthday` defaults to today 28 | // the instance method is invoked *on the instance* 29 | createdPug.celebrateBirthday() // Happy birthday! 30 | ``` 31 | 32 | 33 | ### Class Methods 34 | 35 | The code example below demonstrates a class method. 36 | Class methods are methods that are available on the *model itself* (aka the _class_). 37 | We often write these to get instances, or do something to more than one instance 38 | 39 | ##### Definition 40 | 41 | ```javascript 42 | const Pug = db.define('pugs', {/* etc*/}) 43 | 44 | // class methods are defined right on the model 45 | Pug.findPuppies = function () { 46 | // 'this' refers directly back to the model (the capital "P" Pug) 47 | return this.findAll({ // could also be Pug.findAll 48 | where: { 49 | age: {$lte: 1} // find all pugs where age is less than or equal to 1 50 | } 51 | }) 52 | } 53 | ``` 54 | 55 | ##### Usage 56 | ```javascript 57 | const foundPuppies = await Pug.findPuppies() 58 | console.log('Here are the pups: ', foundPuppies) 59 | ``` 60 | -------------------------------------------------------------------------------- /docs/many-many-associations.md: -------------------------------------------------------------------------------- 1 | One-One and One-Many associations are very similar. Many-Many associations are different! Instead of placing a foreign key in one table, they create a brand new "join" table where each row contains a foreign key for each entity in the relationship. 2 | 3 | For our example, let's introduce a new table, Friend: 4 | 5 | ```js 6 | const Friend = db.define('friends', { 7 | name: Sequelize.STRING 8 | }) 9 | ``` 10 | 11 | A "friend" is a (human) person that is friends with pugs (but not necessarily a pug Owner themselves)! Any given "friend" may be a friend of many pugs. Likewise, any given pug will have many human friends! This is the nature of a many-to-many relationship. 12 | 13 | Here is how we define one: 14 | 15 | ```js 16 | Friend.belongsToMany(Pug, {through: 'friendship'}) 17 | Pug.belongsToMany(Friend, {through: 'friendship'}) 18 | ``` 19 | 20 | The "through" parameter defines the name of the join table that gets created. 21 | 22 | By establishing the relation above, the following *four* things happen: 23 | 24 | 1. A brand new table called `"friendship"` is created. 25 | 26 | *friendship* 27 | ``` 28 | createdAt | updatedAt | pugId | pugFriendId 29 | ``` 30 | 31 | No changes occur to the `pug` or `friend` tables! 32 | 33 | 2. A new Sequelize model becomes automatically generated for the table: 34 | 35 | ```javascript 36 | const Friendship = db.model('friendship') 37 | ``` 38 | 39 | You can use this model the same way you use any other Sequelize model (you can query it, create instances, etc). 40 | 41 | 3. Sequelize automatically creates several instance methods for pugs and for friends, the same ones as created by `hasMany` above: 42 | 43 | ``` 44 | pug.getFriends() // returns a promise for the array of friends for that pug 45 | pug.addFriend(friend) // creates a new row in the friendship table for the pug and the friend, returns a promise for the friendship (NOT the pug OR the friend - the "friendship") 46 | pug.addFriends(friendsArray) // creates a new row in the friendship table for each friend, returns a promise for the friendship 47 | pug.removeFriend(friend) // removes the row from the friendship table for that pug-friend, returns a promise for the number of affected rows (as if you'd want to destroy any friendships...right?) 48 | pug.removeFriends(friendsArray) // removes the rows from the friendship table for those pug-friend pairs, returns a promise for the number affected rows 49 | 50 | // analogous to above ^ 51 | friend.getPugs() 52 | friend.addPug(pug) 53 | friend.addPugs(pugsArray) 54 | friend.setPugs(pugsArray) 55 | friend.removePug(pug) 56 | friend.removePugs(pugsArray) 57 | ``` 58 | 59 | 4. Allows us to include a pug's friends, or a friend's pugs 60 | 61 | ```javascript 62 | const pugsWithFriends = await Pug.findAll({ 63 | include: [{model: Friend}] 64 | }) 65 | 66 | console.log(pugsWithFriends[0]) 67 | // looks like this: 68 | // { 69 | // id: 1, 70 | // name: 'Cody', 71 | // friends: [ 72 | // { 73 | // id: 1, 74 | // name: 'CodyFan <3' 75 | // }, 76 | // ....any many more! 77 | // ] 78 | // } 79 | 80 | ``` 81 | 82 | The inverse also applies if we `Friend.findAll({include: [{model: Pug}]})` 83 | -------------------------------------------------------------------------------- /docs/model-definition.md: -------------------------------------------------------------------------------- 1 | [Official Docs](http://docs.sequelizejs.com/manual/tutorial/models-definition.html) 2 | 3 | To define mappings between a model and a table, use the `define` method. 4 | 5 | ```js 6 | const Pug = db.define('pugs', { 7 | name: Sequelize.STRING, 8 | cute: Sequelize.BOOLEAN, 9 | age: Sequelize.INTEGER, 10 | bio: Sequelize.TEXT 11 | }) 12 | ``` 13 | 14 | You can also set some options on each column: 15 | 16 | ```js 17 | const Pug = db.define('pugs', { 18 | name: { 19 | type: Sequelize.STRING 20 | allowNull: false // name MUST have a value 21 | }, 22 | cute: { 23 | type: Sequelize.BOOLEAN, 24 | defaultValue: true // instantiating will automatically set "cute" to true if not set 25 | }, 26 | bio: Sequelize.TEXT, 27 | age: { 28 | type: Sequelize: INTEGER, 29 | validate: { 30 | min: 0, 31 | max: 100 32 | // note: many validations need to be defined in the "validate" object 33 | // allowNull is so common that it's the exception 34 | } 35 | } 36 | }) 37 | ``` -------------------------------------------------------------------------------- /docs/one-many-associations.md: -------------------------------------------------------------------------------- 1 | A one-many association is established by pairing a `belongsTo` and a `hasMany` relation (though like `hasOne`, the `belongsTo` is sometimes omitted). 2 | 3 | Given our Pug and Owner, we might allow an owner to have multiple pugs like so: 4 | 5 | ```javascript 6 | Pug.belongsTo(Owner) 7 | Owner.hasMany(Pug) 8 | ``` 9 | 10 | This means that a pug belongs to an owner, and an owner can have many pugs (also known as a [grumble](https://www.google.com/search?q=grumble+of+pugs&ie=utf-8&oe=utf-8&client=firefox-b-1-ab)). 11 | 12 | By doing this, the following three things will happen/be available to use: 13 | 14 | 1. The Pug table will have a foreign key column, "ownerId", corresponding to a primary key in the Owner table. *Note: this is the same as a one-one association*. 15 | 16 | *Pugs* - includes an ownerId! 17 | ``` 18 | id | name | createdAt | updatedAt | ownerId 19 | ``` 20 | 21 | *Owner* - no changes! 22 | ``` 23 | id | name | createdAt | updatedAt 24 | ``` 25 | 26 | 2. Sequelize automatically creates three instance methods for pugs, "getOwner", "setOwner", and "createOwner". This is because we defined `Pug.belongsTo(Owner)`. Likewise, owners get a bunch of new instance methods, "getPugs", "setPugs", "createPug", "addPug", "addPugs", "removePug", "removePugs", "hasPug", "hasPugs", and "countPugs" (because we defined `Owner.hasMany(Pug)`). *Note: the difference here from one-one is that the owner's methods are now pluralized, and return promises for arrays of pugs instead of just a single pug!* 27 | 28 | ```javascript 29 | pug.getOwner() // returns a promise for the pug's owner 30 | 31 | pug.setOwner(owner) // updates the pug's ownerId to be the id of the passed-in owner, and returns a promise for the updated pug 32 | 33 | owner.getPugs() // returns a promise for an array of all of the owner's pugs (that is, all pugs with ownerId equal to the owner's id) 34 | 35 | owner.setPugs(arrayOfPugs) 36 | // updates each pug in the passed in array to have an ownerId equal to the owner's id. 37 | // returns a promise for the owner (NOT the pugs) 38 | ``` 39 | 40 | 3. Sequelize will allow us to "include" the pug's owner, or the owner's pugs in queries. 41 | 42 | ```javascript 43 | // this is the same as one-one 44 | const pugsWithTheirOwners = await Pug.findAll({ 45 | include: [{model: Owner}] 46 | }) 47 | 48 | console.log(pugsWithTheirOwners[0]) 49 | // looks like this: 50 | // { 51 | // id: 1, 52 | // name: 'Cody', 53 | // ownerId: 1, 54 | // owner: { 55 | // id: 1, 56 | // name: 'Tom' 57 | // } 58 | // } 59 | ``` 60 | 61 | Likewise (but note that if we do omit the `Owner.hasMany(Pug)`, this is not possible): 62 | 63 | ```javascript 64 | // the difference is that instead of a "pug" field, the owner has a "pugs" field, which is an array of all that owner's pugs 65 | const ownersWithTheirPug = await Owner.findAll({ 66 | include: [{model: 'Pug'}] 67 | }) 68 | 69 | console.log(ownersWithTheirPug[0]) 70 | // looks like this: 71 | // { 72 | // id: 1, 73 | // name: 'Tom', 74 | // pugs: [{ 75 | // id: 1, 76 | // name: 'Cody', 77 | // ownerId: 1 78 | // }] 79 | // } 80 | ``` 81 | -------------------------------------------------------------------------------- /docs/one-one-relations.md: -------------------------------------------------------------------------------- 1 | A one-one association is established by pairing a `belongsTo` and a `hasOne` association (though the `hasOne` is often omitted). 2 | 3 | Say we have two model tables, `Pug` and an `Owner`. We might associate them like so: 4 | 5 | ```javascript 6 | Pug.belongsTo(Owner) 7 | Owner.hasOne(Pug) 8 | ``` 9 | 10 | This means that a pug belongs to an owner, and an owner has one (and only one) pug. 11 | 12 | By doing this, the following three things will happen/be available to use: 13 | 14 | 1. The Pug table will have a foreign key column, "ownerId", corresponding to a primary key in the Owner table. 15 | 16 | *Pugs* - includes an ownerId! 17 | ``` 18 | id | name | createdAt | updatedAt | ownerId 19 | ``` 20 | 21 | *Owner* - no changes! 22 | ``` 23 | id | name | createdAt | updatedAt 24 | ``` 25 | 26 | 2. Sequelize automatically creates two instance methods for pugs, "getOwner" and "setOwner". This is because we defined `Pug.belongsTo(Owner)`. Likewise, owners get two instance methods, "getPug" and "setPug" (because we defined `Owner.hasOne(Pug)`). 27 | 28 | ```javascript 29 | pug.getOwner() // returns a promise for the pug's owner 30 | 31 | pug.setOwner(ownerInstanceOrID) // updates the pug's ownerId to be the id of the passed-in owner, and returns a promise for the updated pug 32 | 33 | owner.getPug() // returns a promise for the owner's pug 34 | 35 | owner.setPug(pugInstanceOrID) // updates the passed-in pug's ownerId to be the id of the owner, and returns a promise for the updated pug 36 | ``` 37 | 38 | 3. Sequelize will allow us to "include" the pug's owner, or the owner's pug in queries. 39 | 40 | ```javascript 41 | const pugsWithTheirOwners = await Pug.findAll({ 42 | include: [{model: Owner}] 43 | }) 44 | 45 | console.log(pugsWithTheirOwners[0]) 46 | // looks like this: 47 | // { 48 | // id: 1, 49 | // name: 'Cody', 50 | // ownerId: 1, 51 | // owner: { 52 | // id: 1, 53 | // name: 'Tom' 54 | // } 55 | // } 56 | ``` 57 | 58 | Likewise (but note that if we do omit the `Owner.hasOne(Pug)`, this is not possible): 59 | 60 | ```javascript 61 | const ownersWithTheirPug = await Owner.findAll({ 62 | include: [{model: 'Pug'}] 63 | }) 64 | 65 | console.log(ownersWithTheirPug[0]) 66 | // looks like this: 67 | // { 68 | // id: 1, 69 | // name: 'Tom', 70 | // pug: { 71 | // id: 1, 72 | // name: 'Cody', 73 | // ownerId: 1 74 | // } 75 | // } 76 | 77 | ``` -------------------------------------------------------------------------------- /docs/querying.md: -------------------------------------------------------------------------------- 1 | # Querying Using Models 2 | 3 | ## Model.findOne 4 | [Official Docs](http://docs.sequelizejs.com/manual/tutorial/models-usage.html#-find-search-for-one-specific-element-in-the-database) 5 | 6 | Finds a single instance that matches the search criteria (even if there are more than one that match the search criteria - it will return the first it finds) 7 | 8 | ```javascript 9 | const foundPug = await Pug.findOne({ 10 | where: {name: 'Cody'} 11 | }) 12 | 13 | console.log(foundPug) 14 | 15 | ``` 16 | 17 | ## Model.findById 18 | [Official Docs](http://docs.sequelizejs.com/manual/tutorial/models-usage.html#-find-search-for-one-specific-element-in-the-database) 19 | 20 | Finds the instance with the specified id. 21 | 22 | ```javascript 23 | pugWithIdOne = await Pug.findById(1) 24 | 25 | console.log(pugWithIdOne) 26 | ``` 27 | ## Model.findAll 28 | [Official Docs](http://docs.sequelizejs.com/manual/tutorial/models-usage.html#-findall-search-for-multiple-elements-in-the-database) 29 | 30 | Finds all instances that match the search criteria. If no criteria are given, it returns all the instances in the table. 31 | 32 | ```javascript 33 | const allPugs = await Pug.findAll() // will find ALL the pugs! 34 | 35 | console.log(allPugs) 36 | ``` 37 | 38 | ### "Select" Clauses ("attributes") 39 | [Official Docs](http://docs.sequelizejs.com/manual/tutorial/querying.html#attributes) 40 | 41 | You can select specific columns to be included in the returned instance by specifying an "attributes" array. 42 | 43 | ```javascript 44 | const allPugs = await Pug.findAll({ 45 | attributes: ['id', 'name', 'age'] // like saying: SELECT id, name, age from pugs; 46 | }) 47 | 48 | console.log(allPugs) // [{id: 1, name: 'Cody', age: 7}, {id: 2, name: "Murphy", age: 4}] 49 | // note that all the pugs only have key-value pairs for id, name and age included 50 | 51 | ``` 52 | 53 | ### "Where" Clauses 54 | [Official Docs](http://docs.sequelizejs.com/manual/tutorial/querying.html#where) 55 | 56 | You can narrow down the search in a `findAll` by specifying a `where` clause 57 | 58 | ```javascript 59 | const sevenYearOldPugs = await Pug.findAll({ 60 | where: { // like saying: SELECT * from pugs WHERE age = 7; 61 | age: 7, 62 | } 63 | }) 64 | 65 | console.log(sevenYearOldPugs) 66 | ``` 67 | 68 | Specifying multiple options uses "AND" logic 69 | 70 | ```javascript 71 | const sevenYearOldBlackPugs = await Pug.findAll({ 72 | where: { // like saying: SELECT * from pugs WHERE age = 7 AND color = 'black'; 73 | age: 7, 74 | color: 'black' 75 | } 76 | }) 77 | 78 | console.log(sevenYearOldBlackPugs) 79 | 80 | ``` 81 | 82 | **Note**: To specify comparisons like "greater than" and "less than", Check out [Search Operators](/search-operators). -------------------------------------------------------------------------------- /docs/search-operators.md: -------------------------------------------------------------------------------- 1 | [Official Docs](http://docs.sequelizejs.com/manual/tutorial/querying.html#operators) 2 | 3 | We often want to specify comparisons like "greater than", "less than" in our `where` clauses. 4 | 5 | In sequelize, we need to use special properties called "operators" to do this. Here are some of the most common. (Note: there are of course many more operators - there's no need to memorize all of them, but be sure to read through them so that you have an idea of what you can do!) 6 | 7 | *Note*: Up until very recently, we used regular object properties to refer to operators. In upcoming versions of Sequelize, these will be replaced by Symbols that must be obtained from Sequelize, like so: 8 | 9 | ```javascript 10 | // Sequelize stores these operators on the `Sequelize.Op` module: 11 | const Op = Sequelize.Op 12 | 13 | Pug.findAll({ 14 | where: { 15 | age: { 16 | [Op.lte]: 7 // square brackets are needed for property names that aren't plain strings 17 | } 18 | } 19 | }) 20 | ``` 21 | 22 | The examples below demonstrate using operators as regular object properties, with the Symbol equivalent in an adjacent comment. 23 | 24 | Here is a list of some of the more commonly used operators, and their usage: 25 | 26 | * $gt: Greater than // soon to be replaced by [Op.gt] 27 | * $gte: Greater than or equal // soon to be replaced by [Op.gte] 28 | * $lt: Less than // soon to be replaced by [Op.lt] 29 | * $lte: Less than or equal // soon to be replaced by [Op.lte] 30 | * $ne: Not equal // soon to be replaced by [Op.ne] 31 | * $eq: Equal // soon to be replaced by [Op.eq] 32 | * $or: Use or logic for multiple properties // soon to be replaced by [Op.or] 33 | 34 | 35 | ```javascript 36 | // gt, gte, lt, lte 37 | 38 | // SELECT * FROM pugs WHERE age <= 7 39 | Pug.findAll({ 40 | where: { 41 | age: { 42 | $lte: 7 // soon to be replaced by [Op.lte] 43 | } 44 | } 45 | }) 46 | ``` 47 | 48 | ```javascript 49 | // $ne 50 | 51 | // SELECT * FROM pugs WHERE age != 7 52 | Pug.findAll({ 53 | where: { 54 | age: { 55 | $ne: 7 // soon to be replaced by [Op.ne] 56 | } 57 | } 58 | }) 59 | ``` 60 | 61 | ```javascript 62 | // $or 63 | 64 | // SELECT * FROM pugs WHERE age = 7 OR age = 6 65 | Pug.findAll({ 66 | where: { 67 | age: { 68 | $or: [ // soon to be replaced by [Op.or] 69 | {$eq: 7}, // soon to be replaced by [Op.eq] 70 | {$eq: 6} // soon to be replaced by [Op.eq] 71 | ] 72 | } 73 | } 74 | }) 75 | ``` 76 | -------------------------------------------------------------------------------- /docs/validators-and-default-values.md: -------------------------------------------------------------------------------- 1 | [Official Docs](http://docs.sequelizejs.com/manual/tutorial/models-definition.html#validations) 2 | 3 | The example below demontrates usage for important validations (allowNull, min/max) and also demonstrates how to set a default value (defaultValue) 4 | 5 | ```javascript 6 | const Pug = db.define('pugs', { 7 | name: { 8 | type: Sequelize.STRING 9 | allowNull: false // name MUST have a value 10 | }, 11 | bio: { 12 | name: Sequelize.TEXT 13 | }, 14 | age: { 15 | type: Sequelize.INTEGER, 16 | validate: { 17 | min: 0, 18 | max: 100 19 | // note: many validations need to be defined in the "validate" object 20 | // allowNull is so common that it's the exception 21 | } 22 | }, 23 | birthday: { 24 | type: Sequelize.DATE, 25 | defaultValue: Date.now() 26 | // if no birthday is specified when we create the row, it defaults to right now! 27 | }, 28 | colors: { 29 | type: Sequelize.ENUM('black', 'fawn') 30 | }, 31 | toys: { 32 | type: Sequelize.ARRAY(Sequelize.TEXT) 33 | }, 34 | adoptedStatus: { 35 | type: Sequelize.BOOLEAN 36 | } 37 | }) 38 | ``` 39 | -------------------------------------------------------------------------------- /docs/virtual-columns.md: -------------------------------------------------------------------------------- 1 | "Virtual" columns are columns that *do not* get saved in your database - they are calculated on the fly based on the values of other columns. They are helpful for saving space if there are values we want to use on our instances that can be easily calculated. 2 | 3 | Virtual columns always have the data type of Sequelize.VIRTUAL. 4 | 5 | Virtual columns must have *at least* one custom 'getter' or 'setter' to be useful. This does not mean that getters and setters can _only_ be used with virtual columns though (see above). 6 | 7 | Virtual columns are similar to instance methods. The difference is you access virtual columns the same way you access a regular property (via the 'get' and 'set' meta-operation), whereas instance methods are functions that you must invoke. 8 | 9 | ##### Definition 10 | 11 | ```javascript 12 | const Pug = db.define('pugs', { 13 | firstName: { 14 | type: Sequelize.STRING, 15 | }, 16 | lastName: { 17 | type: Sequelize.STRING 18 | }, 19 | fullName: { 20 | type: Sequelize.VIRTUAL, 21 | get () { 22 | return this.getDataValue('firstName') + ' ' + this.getDataValue('lastName') 23 | } 24 | } 25 | }) 26 | ``` 27 | 28 | ##### Usage 29 | 30 | ```javascript 31 | const pug = await Pug.create({firstName: 'Cody', lastName: 'McPug'}) 32 | 33 | console.log(pug.fullName) // "Cody McPug" 34 | // however, if you look inside your database, there won't be a "fullName" column! 35 | ``` 36 | -------------------------------------------------------------------------------- /mkdocs.yml: -------------------------------------------------------------------------------- 1 | site_name: Sequelize Guides 2 | site_url: http://www.mkdocs.org 3 | site_description: Sequelize simple documentation. 4 | site_author: Tom Kelly, Fullstack team and contributors. 5 | repo_url: https://github.com/FullstackAcademy/SequelizeGuides 6 | edit_uri: "" 7 | pages: 8 | - Home: "index.md" 9 | - Getting Started: "getting-started.md" 10 | - Model: 11 | - Definition: "model-definition.md" 12 | - Column Types: "column-types.md" 13 | - Validators and Default Values: "validators-and-default-values.md" 14 | - Hooks: "hooks.md" 15 | - Instance and Class Methods: "instance-and-class-methods.md" 16 | - Getters and Setters: "getters-and-setters.md" 17 | - Virtual Columns: "virtual-columns.md" 18 | - Querying Models: "querying.md" 19 | - Search Operators: "search-operators.md" 20 | - "Inserting, updating and destroying": "inserting-updating-destroying.md" 21 | - Associations: 22 | - Association Types: "association-types.md" 23 | - One-One Relations: "one-one-relations.md" 24 | - One-Many Associations: "one-many-associations.md" 25 | - Many-Many Associations: "many-many-associations.md" 26 | - Eager Loading: "eager-loading.md" 27 | theme: readthedocs 28 | extra_css: 29 | - css/extra.css 30 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | botocore==1.6.3 2 | chardet==3.0.4 3 | click==6.7 4 | colorama==0.3.7 5 | docopt==0.6.2 6 | docutils==0.14 7 | idna==2.6 8 | itsdangerous==0.24 9 | jmespath==0.9.3 10 | Markdown==2.6.11 11 | MarkupSafe==1.0 12 | mkdocs==0.17.2 13 | pipreqs==0.4.9 14 | PyYAML==3.12 15 | tornado==4.5.3 16 | urllib3==1.22 17 | yarg==0.1.9 -------------------------------------------------------------------------------- /runtime.txt: -------------------------------------------------------------------------------- 1 | 3.4.0 --------------------------------------------------------------------------------