Skip to content

Instantly share code, notes, and snippets.

-- the function to call when the trigger is invoked
CREATE FUNCTION trigger_on_note_revision()
RETURNS TRIGGER
LANGUAGE PLPGSQL AS $BODY$
BEGIN
-- Create revision only if node's subject or body columns have changed
IF OLD.title <> NEW.title OR OLD."data" <> NEW."data" THEN
INSERT INTO note_revision (note_id, created_at, title, "data")
VALUES (OLD.id, OLD.updated_at, OLD.title, OLD."data");
NEW.updated_at = now();
-- Create the function
CREATE FUNCTION insert_deposit()
RETURNS trigger AS $BODY$
DECLARE active_account BOOLEAN;
BEGIN
IF NEW."deposit_amount" <= 0 THEN
RAISE EXCEPTION 'Deposit amount must be greater than 0';
END IF;
SELECT a.is_active INTO active_account FROM "account_savings" a WHERE a.account_no = NEW."account_no";
IF active_account != TRUE THEN
version: '2'
services:
graphql-engine:
image: hasura/graphql-engine:latest
ports:
- '80:8080'
restart: always
environment:
HASURA_GRAPHQL_DATABASE_URL: postgres://<rds-user>:<rds-password>@<rds-instance>:5432/<rds-dbname>
HASURA_GRAPHQL_ACCESS_KEY: mylongsecretaccesskey
mutation update_drafts {
update_article(
where: {author: {name: {_eq: "John"}}},
_set: {is_published: true}
) {
affected_rows
}
}
mutation update_likes {
update_article(
where: {id: {_eq: 1}},
_inc: {likes: 1}
) {
affected_rows
returning {
id
likes
}
mutation update_title_content {
update_article(
where: {id: {_eq: 1}},
_set: {
title: "John's new first post title",
content: "New content for John's first post"
}
) {
affected_rows
returning {
@ecthiender
ecthiender / hge-blog-generated-update-mutations.graphql
Last active August 13, 2018 06:23
Generated update mutations by HGE
update_author(
_inc: author_inc_input
_set: author_set_input
where: author_bool_exp!
): author_mutation_response
author_set_input {
id: Int
name: String
}
@ecthiender
ecthiender / hge-blog-update-mutations-schema.sql
Last active August 13, 2018 06:12
Sample schema for update mutations
CREATE TABLE author (
id INTEGER PRIMARY KEY,
name TEXT
);
CREATE TABLE article (
id INTEGER PRIMARY KEY,
title TEXT,
content TEXT,
author_id INTEGER,
@ecthiender
ecthiender / main.hs
Created August 30, 2017 18:59 — forked from thsutton/main.hs
Monad logger
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Control.Applicative
import Control.Monad.Except
import Control.Monad.IO.Class ()
import Control.Monad.Reader
@ecthiender
ecthiender / citrus_1.py
Created September 10, 2015 22:11
Some limey functions!
# -*- coding: utf8 -*-
# Some limey functions!
from functools import reduce
import itertools
import unittest
def omit(x, li):