Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I run arbitrary queries on the same connection? #13

Open
nickretallack opened this issue Jun 18, 2011 · 2 comments
Open

Can I run arbitrary queries on the same connection? #13

nickretallack opened this issue Jun 18, 2011 · 2 comments

Comments

@nickretallack
Copy link

I still don't understand how to get a many-to-many query working, and I'm sure there are queries I'd like to do that this system doesn't support. Is it possible to run arbitrary queries using the same database connection? Could the API expose that functionality?

I noticed it just attaches a pg client at FastLegS.client.client, but it doesn't seem to actually execute queries that I run on it.

@Wilfred
Copy link

Wilfred commented Jul 3, 2011

Seems to work for me:

> var FastLegS = require('FastLegS');
> var myQuery = 'select * from posts;';
> FastLegS.client.emit('query', query, function(err, result) {
>         console.log(result)
> });
rows: [ { id: null, title: 'Some Title 1', body: 'Some body 1' } ], command: 'SELECT', rowCount: 1, oid: NaN }

I've been trying to throw together some basic docs at https://github.com/Wilfred/FastLegS/wiki , feel free to add to them.

@Wilfred
Copy link

Wilfred commented Jul 10, 2011

That repo has been removed, here's the old wiki content:

FastLegS Documentation

Models

Defining Models

You need to create the tables yourself, FastLegS will not do table creation. To create a model, extend FastLegS.Base with the columns of the table:

var FastLegS = require('FastLegS');

var Post = FastLegS.Base.extend({
  tableName: 'posts',
  primaryKey: 'id'
});

FIXME: is it necessary to list all of the columns in the model definition?

Querying Models

Base has a find() method which queries and returns objects matching your query. The syntax is:

MyModel.find(selector, options, callback);

selector can be a single primary key:

MyModel.find(1, {}, function(err, items) {
  console.log(items);
});

or it can be an array of possible primary keys:

MyModel.find([23, 29], {}, function(err, items) {
  console.log(items);
});

or it can be an object specifying column values that the objects must have:

MyModel.find({'name': 'James Bond', 'occupation':'Spy'}, {}, function(err, items) {
  console.log(items);
});

There is also a findOne() convenience method, which is equivalent to setting limit to one in the options.

Raw SQL

var FastLegS = require('FastLegS');

var myQuery = 'select * from posts;';
FastLegS.client.emit('query', query, function(err, result) {
        console.log(result)
});

MyModel

Running the tests

$ make test

(requires expresso)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants