Skip to content

Instantly share code, notes, and snippets.

View danielrearden's full-sized avatar

Daniel Rearden danielrearden

View GitHub Profile
@danielrearden
danielrearden / createMockRow.js
Last active July 20, 2017 19:17
createMockRow
const chance = require('chance')
module.exports = (db, table, specificProps) => db.raw(`
SELECT column_name, data_type
FROM information_schema.columns
WHERE table_name = '${table}';
`).then((cols) => cols.reduce((memo, col) => {
switch (col.data_type) {
case 'uuid': return Object.assign({ [col.column_name]: chance.guid() }, memo);
case 'character varying': return Object.assign({ [col.column_name]: chance.word() }, memo);
import crypto from 'crypto'
import redis from 'services/redis'
export async function queryWrapper (query, ttl) {
// these could also be passed explicitly to the function, but that may leave more room for error?
let table, method
query.modify(qb => {
table = qb._table || 'some_fallback'
method = qb._method
})

Keybase proof

I hereby claim:

  • I am danielrearden on github.
  • I am danielrearden (https://keybase.io/danielrearden) on keybase.
  • I have a public key ASCcI8cGL1AfbfSgjEtpUtk5ELxgPuHf9mZqLdbEjz8EbQo

To claim this, I am signing this object:

@danielrearden
danielrearden / schema.graphql
Created May 15, 2020 04:06
Making GraphQL Magic with Sqlmancer - 1
type Customer @model(
table: "customers"
pk: "CustomerId"
) {
id: ID! @col(name: "CustomerId")
firstName: String!
lastName: String!
email: String!
}
@danielrearden
danielrearden / schema.graphql
Created May 15, 2020 04:07
Making GraphQL Magic with Sqlmancer - 2
type Query @sqlmancer(
dialect: SQLITE
transformFieldNames: PASCAL_CASE
) {
customers: [Customer!]!
}
@danielrearden
danielrearden / schema.graphql
Last active May 15, 2020 04:08
Making GraphQL Magic with Sqlmancer - 3
type Customer @model(
table: "customers"
pk: "CustomerId"
) {
id: ID! @col(name: "CustomerId")
firstName: String!
lastName: String!
email: String!
invoices: [Invoice!]!
@relate(on: { from: "CustomerId", to: "CustomerId" })
@danielrearden
danielrearden / schema.graphql
Created May 15, 2020 04:09
Making GraphQL Magic with Sqlmancer - 4
type Query @sqlmancer(
dialect: POSTGRES
transformFieldNames: PASCAL_CASE
) {
customers: [Customer!]! @where @orderBy @limit @offset
invoices: [Invoice!]! @many
}
@danielrearden
danielrearden / schema.graphql
Created May 15, 2020 04:09
Making GraphQL Magic with Sqlmancer - 5
invoices: [Invoice!]!
@relate(on: { from: "CustomerId", to: "CustomerId" })
@many
@danielrearden
danielrearden / index.ts
Created May 15, 2020 04:10
Making GraphQL Magic with Sqlmancer - 6
import Knex from "knex";
const knex = Knex({
client: "sqlite3",
connection: {
filename: "./sample.db"
}
});
@danielrearden
danielrearden / index.ts
Created May 15, 2020 04:10
Making GraphQL Magic with Sqlmancer - 7
import { createSqlmancerClient } from "sqlmancer";
const client = createSqlmancerClient(__filename, knex);