Skip to content

Instantly share code, notes, and snippets.

-- Lets say I have a query like the one here that retrieves a single message from database.
-- Each message is supposed to have a `seen_by` column that includes the array of people
-- Who have seen the message.
SELECT
id,
comment,
author,
(
SELECT ARRAY_AGG("user") FROM messages_users WHERE messages_users.message = messages.id AND seen_at IS NOT NULL
) as seen_by
emilsedgh@debian ~/P/r/server> git push alpine develop:master
Counting objects: 166, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (166/166), done.
Writing objects: 100% (166/166), 17.24 KiB | 0 bytes/s, done.
Total 166 (delta 135), reused 0 (delta 0)
-----> Cleaning up...
-----> Building alpine from dockerfile...
-----> Setting config vars
DOKKU_DOCKERFILE_PORTS: 3078
CREATE OR REPLACE FUNCTION get_brand_users(uuid, uuid) RETURNS
setof uuid
AS
$$
WITH brand_users AS (
SELECT DISTINCT users.id FROM users
LEFT JOIN agents ON users.agent = agents.id
LEFT JOIN offices ON agents.office_mui = offices.matrix_unique_id
LEFT JOIN brands_offices ON offices.id = brands_offices.office
LEFT JOIN brands_agents ON agents.id = brands_agents.agent
CREATE OR REPLACE FUNCTION get_brand_users(uuid, uuid) RETURNS
setof uuid
AS
$$
WITH brand_users AS (
SELECT DISTINCT users.id FROM users
LEFT JOIN agents ON users.agent = agents.id
LEFT JOIN offices ON agents.office_mui = offices.matrix_unique_id
LEFT JOIN brands_offices ON offices.id = brands_offices.office
LEFT JOIN brands_agents ON agents.id = brands_agents.agent
// This is a method I have that ideally should look like this:
Token.create = async token => {
const result = await query.promise('token/insert', [
token.client_id,
token.user_id,
token.type,
])
return 'something'
a = cb => {
cb()
}
b = cb => {
a(cb)
}
a.promisified = promisify(a)

Keybase proof

I hereby claim:

  • I am emilsedgh on github.
  • I am emilsedgh (https://keybase.io/emilsedgh) on keybase.
  • I have a public key whose fingerprint is E26F E6FA B023 0AC7 B61A CAE7 1E77 9FF7 23B7 D6F2

To claim this, I am signing this object:

@emilsedgh
emilsedgh / atomic.js
Created January 23, 2016 01:58
Atomic endpoints using domains
var db = require('./db.js');
var Domain = require('domain');
function transaction(req, res, next) {
db.conn(function(err, conn, done) {
var domain = Domain.create();
if(err) {
return next(Error.Database(err));
}
@emilsedgh
emilsedgh / gist:8987b4e580dd2e1b792a
Created January 23, 2016 01:57
Domains helping atomic endpoints
var db = require('./db.js');
var Domain = require('domain');
function transaction(req, res, next) {
db.conn(function(err, conn, done) {
var domain = Domain.create();
if(err) {
return next(Error.Database(err));
}
This file has been truncated, but you can view the full file.
{"snapshot":{"title":"","uid":1,"meta":{"node_fields":["type","name","id","self_size","edge_count"],"node_types":[["hidden","array","string","object","code","closure","regexp","number","native","synthetic"],"string","number","number","number","number","number"],"edge_fields":["type","name_or_index","to_node"],"edge_types":[["context","element","property","internal","hidden","shortcut","weak"],"string_or_number","node"]},"node_count":18361,"edge_count":99871},
"nodes":[3,1,1,0,3
,3,2,3,0,12
,3,3,9,0,193
,3,4,11,0,1
,3,5,31,0,1
,3,6,15,0,33
,3,7,17,0,3
,3,8,19,0,2
,3,9,21,0,11