This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION public.json_append(data json, insert_data json) | |
RETURNS json | |
IMMUTABLE | |
LANGUAGE sql | |
AS $$ | |
SELECT ('{'||string_agg(to_json(key)||':'||value, ',')||'}')::json | |
FROM ( | |
SELECT * FROM json_each(data) | |
UNION ALL | |
SELECT * FROM json_each(insert_data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | |
-- PostgreSQL database dump | |
-- | |
SET statement_timeout = 0; | |
SET client_encoding = 'UTF8'; | |
SET standard_conforming_strings = on; | |
SET check_function_bodies = false; | |
SET client_min_messages = warning; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE IF NOT EXISTS sample_table ( | |
id serial, | |
field1 text, | |
field2 int, | |
field3 date | |
); | |
INSERT INTO sample_table (field1, field2, field3) | |
SELECT | |
md5(random()::text), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import without from 'lodash/array/without'; | |
const FIELD_SEPERATOR = ', '; | |
// table public fields | |
export const ACCOUNT_FIELDS = ['id', 'username', 'email', 'phone', 'password', 'status', 'type', 'created_at']; | |
export const PARENT_FIELDS = ['account_id', 'activated_at']; | |
export const EXPERT_FIELDS = ['account_id', 'activated_at']; | |
export const PROFILE_FIELDS = ['account_id', 'display_name', 'avatar_url', 'location_id', 'updated_at']; | |
export const LOCATION_FIELDS = ['id', 'country', 'province', 'city', 'district', 'street', 'street_number', 'lat', 'lng', 'created_at']; | |
export const COMMUNITY_FIELDS = ['id', 'location_id', 'name', 'description', 'signature', 'notice', 'cover_image_url', 'member_counts', 'rules', 'join_restrict', 'join_review', 'join_review_question', 'join_review_question', 'visible_on_search', 'status', 'created_at']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Demo of PostgreSQL 9.5 features for Wellington PostgreSQL User's Group | |
-- The following is not necessarily in the right order or exactly how I ran it, | |
-- I mixed it up a bit when presenting! | |
DROP TABLE IF EXISTS country CASCADE; | |
DROP TABLE IF EXISTS sales_per_person CASCADE; | |
DROP TABLE IF EXISTS film CASCADE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH in_radius AS ( | |
SELECT id | |
FROM table | |
WHERE earth_box( ll_to_earth( 51.534901, -0.204573), 5000.00) @> ll_to_earth(table.lat, table.lng) | |
), results AS ( | |
SELECT * | |
FROM spaces | |
WHERE id IN (SELECT id FROM in_radius) | |
) | |
SELECT *, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
export default function flattenReactChildrenToArray(nodeChildren, accumulated = []) { | |
React.Children.forEach(nodeChildren, (childNode) => { | |
accumulated.push(childNode); | |
if (childNode && childNode.props && childNode.props.children) { | |
flattenReactChildrenToArray(childNode.props.children, accumulated); | |
} | |
}); | |
return accumulated; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create table departments | |
( | |
dept_id integer primary key, | |
dept_name varchar(255) | |
); | |
create table employees | |
( | |
emp_id integer primary key, | |
emp_name varchar(255), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Dockerfile for Flarum, based on Flarum's Vagrantfile | |
# (https://github.com/flarum/flarum/blob/master/Vagrantfile) | |
# which uses scripts from Vaprobash | |
# (https://github.com/fideloper/Vaprobash) | |
# Run with: | |
# docker-compose up flarum | |
# docker-compose run --service-ports flarum <custom command, e.g. /bin/bash> | |
FROM phusion/baseimage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE DATABASE xixi; | |
/** | |
* accounts | |
*/ | |
CREATE TABLE accounts ( | |
id bigserial UNIQUE NOT NULL, | |
-- UNIQUE is needed | |
-- http://www.postgresql.org/docs/9.5/static/datatype-numeric.html#DATATYPE-SERIAL | |
-- |
NewerOlder