Skip to content

Instantly share code, notes, and snippets.

@mattboutet
mattboutet / postgres_queries_and_commands.sql
Created May 18, 2020 23:51 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@mattboutet
mattboutet / knexPostgresFullTextSearch.js
Created April 24, 2019 17:12 — forked from cameronblandford/knexPostgresFullTextSearch.js
Implement full text search using Knex + Objection
// Because we're using an ORM (Objection), it's a pain to add a tsvector when inserting,
// since tsvectors and FTS aren't supported by Objection. Instead, I've added a hook that
// fires on insert which auto-generates the tsvector field for each newly inserted entry.
// This is an example knex migration file for said behavior.
const addUserIndex = `
ALTER TABLE public.user ADD "document" tsvector;
CREATE FUNCTION my_trigger_function()
RETURNS trigger AS $$
@mattboutet
mattboutet / gist:2882e73ec3d993a3a1477017e90211b0
Created March 24, 2018 13:06 — forked from devinivy/deploy.sh
Publish a hapi pal flavor
# Ensure flavor and pal branch are up-to-date locally
git checkout flavor-<name> # Go to the flavor branch
git merge pal/pal # Ensure we're not squashing irrelevant changes, e.g. to the readme
git push pal flavor-<name> # Push the updated flavor branch

git reset pal/pal # See the changes as they appear on top of the main pal branch
git checkout --detach # Leave the current branch– at this point we dont need to update any branch
git add ... # List updated files
git commit -m "(flavor) <name> v<major>.<minor>.<patch>" # Create the squashed commit