This gist is part of a blog post. Check it out at:
http://jasonrudolph.com/blog/2011/08/09/programming-achievements-how-to-level-up-as-a-developer
var express = require('express'), | |
request = require('request'), | |
BufferList = require('bufferlist').BufferList, | |
sys = require('sys'); | |
var app = express.createServer( | |
express.logger(), | |
express.bodyDecoder() | |
); |
### | |
Module dependencies | |
### | |
require.paths.unshift "#{__dirname}/lib/support/express-csrf/" | |
require.paths.unshift "#{__dirname}/lib/support/node_hash/lib/" | |
express = require 'express' | |
app = module.exports = express.createServer() | |
RedisStore = require 'connect-redis' |
This gist is part of a blog post. Check it out at:
http://jasonrudolph.com/blog/2011/08/09/programming-achievements-how-to-level-up-as-a-developer
/** | |
* Modified from the Connect project: https://github.com/senchalabs/connect/blob/master/lib/middleware/errorHandler.js | |
* | |
* Flexible error handler, providing (_optional_) stack traces and logging | |
* and error message responses for requests accepting text, html, or json. | |
* | |
* Options: | |
* | |
* - `showStack` respond with both the error message and stack trace. Defaults to `false` | |
* - `showMessage`, respond with the exception message only. Defaults to `false` |
Latency Comparison Numbers (~2012) | |
---------------------------------- | |
L1 cache reference 0.5 ns | |
Branch mispredict 5 ns | |
L2 cache reference 7 ns 14x L1 cache | |
Mutex lock/unlock 25 ns | |
Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
Compress 1K bytes with Zippy 3,000 ns 3 us | |
Send 1K bytes over 1 Gbps network 10,000 ns 10 us | |
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD |
Computing | |
Paul E. Ceruzzi | |
ISBN: 9780262517676 | |
Modeling Business Processes | |
Wil van der Aalst and Christian Stahl | |
ISBN: 9780262015387 | |
The Reasoned Schemer | |
Daniel P. Friedman, William E. Byrd, and Oleg Kiselyov |
import Html exposing (..) | |
import Keyboard | |
import Window exposing (Size) | |
import AnimationFrame | |
import Task | |
import Html.App as App | |
import Collage exposing (..) | |
import Element exposing (..) |
-- See this document for more information on making Pong: | |
-- http://elm-lang.org/blog/pong | |
import Color exposing (..) | |
import Collage exposing (..) | |
import Element exposing (..) | |
import Keyboard | |
import Text | |
import Time exposing (..) | |
import Window exposing (Size) | |
import Html.App as App |
module Counter exposing (..) | |
import Html exposing (..) | |
import Html.Attributes exposing (style) | |
import Html.Events exposing (onClick) | |
-- MODEL | |
type alias Model = Int |
When querying your database in Sequelize, you'll often want data associated with a particular model which isn't in the model's table directly. This data is usually typically associated through join tables (e.g. a 'hasMany' or 'belongsToMany' association), or a foreign key (e.g. a 'hasOne' or 'belongsTo' association).
When you query, you'll receive just the rows you've looked for. With eager loading, you'll also get any associated data. For some reason, I can never remember the proper way to do eager loading when writing my Sequelize queries. I've seen others struggle with the same thing.
Eager loading is confusing because the 'include' that is uses has unfamiliar fields is set in an array rather than just an object.
So let's go through the one query that's worth memorizing to handle your eager loading.