Skip to content

Instantly share code, notes, and snippets.

View ricardograca's full-sized avatar

Ricardo Graça ricardograca

  • devius.net
  • Portugal
View GitHub Profile
@ricardograca
ricardograca / index.js
Last active December 9, 2018 00:37
Bookshelf previousAttributes() on updated event
var assert = require('assert')
var knex = require('knex')({
client: 'sqlite3',
connection: {filename: ':memory:'}
})
var bookshelf = require('bookshelf')(knex)
var User = bookshelf.Model.extend({
tableName: 'users',
initialize: function() {
this.on('updated', function(user) {
@ricardograca
ricardograca / index.js
Last active May 24, 2018 16:49
Loading Bookshelf models
/*
* This will load all model files that exist in the same directory and attach them to the `models` variable.
* You can then simply require this file whenever you need it in your application and access the model you
* need:
*
* var models = require('./models/index.js')
* var FooModel = models.FooModel
*/
var Bookshelf = require('bookshelf')
var fs = require('fs')
@ricardograca
ricardograca / index.js
Created March 4, 2018 19:30
MySQL rounding dates with Knex
var assert = require('assert')
var knex = require('knex')
var mysql = knex({
client: 'mysql',
connection: {
database: 'bookshelf_test',
user: 'root',
encoding: 'utf8'
}
})
@ricardograca
ricardograca / gist:77d6224a18759ba26312
Last active May 24, 2018 16:52
Lua code style stuff
local registerLink = display.newText({
parent = loginGroup,
text = "Not yet registered?",
font = native.systemFont,
fontSize = 16
}, {
anchorX = 1,
anchorY = 0.5,
x = rightMargin,
y = contentTop + 240,
@ricardograca
ricardograca / package.json
Last active January 15, 2018 15:00
Bookshelf bug - belongsToMany and fetchAll
{
"name": "bookshelf-bug",
"version": "0.1.0",
"dependencies": {
"bookshelf": "*",
"bluebird": "*",
"knex": "*",
"sqlite3": "*"
}
}