Skip to content

Instantly share code, notes, and snippets.

@tmurphree
tmurphree / Include-in-Sequelize.md
Created November 13, 2018 14:53 — forked from zcaceres/Include-in-Sequelize.md
using Include in sequelize

'Include' in Sequelize: The One Confusing Query That You Should Memorize

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.

The Basic Query

@tmurphree
tmurphree / docker-rm-images.md
Last active January 10, 2019 20:33 — forked from alferov/docker-rm-images.md
Remove all (untagged) images and containers from Docker

Clean up the whole mess

docker system prune

For the rest, syntax is:

  • bash
  • PowerShell

Delete all containers

docker rm $(docker ps -aq)

@tmurphree
tmurphree / docker-compose.yaml
Created February 28, 2020 04:06
docker-compose file for elasticsearch with kibana
# elasticsearch will be available on http://localhost:9200
# kibana will be available on http://localhost:5601
version: '3.7'
services:
elasticsearchnode01:
environment:
# Use single node discovery in order to disable production mode and avoid bootstrap checks
# see https://www.elastic.co/guide/en/elasticsearch/reference/current/bootstrap-checks.html
discovery.type: single-node
@tmurphree
tmurphree / docker-compose.yaml
Last active November 12, 2020 21:00
docker-compose file for postgres with a volume mapped to localhost
version: '3.8'
# see https://hub.docker.com/_/postgres for information on the environment variables
services:
database:
image: postgres:13.0-alpine
restart: always
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: example
@tmurphree
tmurphree / deployLambda.sh
Created December 2, 2020 16:01
AWS Lambda zip deployment bash script
#!/bin/bash
FILE_PATH="tmp/lambdaDeployment.zip";
FUNCTION_NAME="tm-test";
rm -f $FILE_PATH;
# make zip with with a whitelist
zip -r $FILE_PATH . -i package*.json "src/*" "node_modules/*";