Skip to content

Instantly share code, notes, and snippets.

@mfpiccolo
Last active April 20, 2016 03:16
Show Gist options
  • Save mfpiccolo/9db5fb91cef8de578bbd2f5ef0d54d84 to your computer and use it in GitHub Desktop.
Save mfpiccolo/9db5fb91cef8de578bbd2f5ef0d54d84 to your computer and use it in GitHub Desktop.
Concept for ruby-diesel
var diesel = require("diesel")
var User = require('User');
diesel.config({
infer_schema = true
infer_models = true # I was thinking this would create Queriable structs with sane defaults based on schema
database_url = "postgres://localhost/ruby_diesel_dev"
model_mapping: {
users: User
}
});
var diesel = require("diesel")
var usesr_table = diesel.users;
users = users_table.filter(diesel.users_table.first_name.eq(string))
.limit(1)
.load() // would call diesel_load internally with an array of commands/query_fragments?
users // [User]
// setup for Neon (or FFI)
fn load(call: Call) -> JsResult<JsString> {
let commands: Handle<JsArray> = try!(try!(call.arguments.require(scope, 0)).check::<JsArray>());
let records = build_query!(commands); // Possible?
// Other fancy stuff
Ok(JsArray::new(scope, records.unwrap())
}
register_module!(m, {
m.export("load", load)
});
class User {
constructor(id, first_name, last_name, email) {
this.id = id;
this.first_name = first_name;
this.last_name = last_name;
this.email = email;
}
}
module.exports = User;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment