Skip to content

Instantly share code, notes, and snippets.

@BrainBacon
Created February 20, 2016 07:24
Show Gist options
  • Save BrainBacon/29dd62533ec64da44021 to your computer and use it in GitHub Desktop.
Save BrainBacon/29dd62533ec64da44021 to your computer and use it in GitHub Desktop.
Fritz example server file
'use strict';
var fritz = require('fritz')();
var profile = class extends fritz.model({
table: 'Profile',
properties: {
email: fritz.model.valid.email,
bio: fritz.model.valid.nullable
},
queries: {
getAll: `
select *
from Profile;
`,
getByEmail: `
select *
from Profile
where data->>'email' = $1;
`
}
}) {
// Profile specific class structure
constructor() {
super(obj);
}
};
fritz.route('api/v1/profile', function(method) {
method.get('all', function() {
return profile.getAll().then(function(result) {
return result.rows;
});
});
method.post('email', function(req, body) {
return profile.getByEmail(body.email).then(function(result) {
return result.rows;
});
});
});
fritz.start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment