ErlyORM / boss_db

BossDB: a sharded, caching, pooling, evented ORM for Erlang
Other
277 stars 138 forks source link

Find by sql #176

Closed davidw closed 10 years ago

davidw commented 10 years ago

This fixes https://github.com/ChicagoBoss/boss_db/issues/175 by creating a find_by_sql.

It's likely that we should change the form some to accommodate non-sql using databases.

rambocoder commented 10 years ago

+1 changing rebar.conf dep to epgsql/epgsql :)

davidw commented 10 years ago

Further thoughts on this?

choptastic commented 10 years ago

This seems like a good idea to me still. I'd like to look to adding it to at least the MySQL adapter as well.

I can do that.

-Jesse

On Mon, May 12, 2014 at 9:56 AM, David N. Welton notifications@github.comwrote:

Further thoughts on this?

— Reply to this email directly or view it on GitHubhttps://github.com/ChicagoBoss/boss_db/pull/176#issuecomment-42842224 .

Jesse Gumm Owner, Sigma Star Systems 414.940.4866 || sigma-star.com || @jessegumm

choptastic commented 10 years ago

I have this merged into my local branch, and I'm working on the mysql version. One thing, so that I ensure that the adjustment is done correctly, it appears from the epgsql readme that the replacement is done like:

boss_db:find_by_sql(person, "Select * from person where a=$1 and b=$2", [A, B]).

The way I've currently done the mysql version is it will crash if $3 is referenced but the provided parameter list only has 2 elements, but is perfectly acceptable to have unreferenced parameters.

So:

This will crash (because there is no 2nd parameter). boss_db:find_by_sql(person, "Select * from person where a=$1 and b=$2", [A]).

And this will be accepted, even though B is never referenced: boss_db:find_by_sql(person, "Select * from person where a=$1 and b=$3", [A, B, C]).

Is this correct?

davidw commented 10 years ago

With Postgres, ultimately it gets turned into:

        Res = pgsql:equery(Conn, Sql, Parameters),

So I think that it's going to be somewhat database specific.

I'm still not 100% convinced about the name, perhaps it'd be nice to give it another one that's less SQL specific, for all the people using other stuff. Nothing comes to mind though.

choptastic commented 10 years ago

What I was asking was if I have the replacement method down. Like params must be $1, $2, $3, and correspond to the specific elements in Parameters? Parameters isn't like a proplist, right? It's just a list, and the params in the SQL can't be named like $name or $id or whatnot, correct?

I want to make sure the syntax is still exchangeable between MySQL and Postgre.

Frankly, I think "find_by_sql" is fine, since it's not pertinent to non-SQL databases, so I wouldn't sweat it for now.

-Jesse

On Fri, May 16, 2014 at 4:45 AM, David N. Welton notifications@github.comwrote:

With Postgres, ultimately it gets turned into:

    Res = pgsql:equery(Conn, Sql, Parameters),

So I think that it's going to be somewhat database specific.

I'm still not 100% convinced about the name, perhaps it'd be nice to give it another one that's less SQL specific, for all the people using other stuff. Nothing comes to mind though.

— Reply to this email directly or view it on GitHubhttps://github.com/ChicagoBoss/boss_db/pull/176#issuecomment-43314592 .

Jesse Gumm Owner, Sigma Star Systems 414.940.4866 || sigma-star.com || @jessegumm

davidw commented 10 years ago

On Postgres, it's like that, yeah. It's just a list, not a proplist. I have no idea if they can have names; I just use the numbers.