-
Notifications
You must be signed in to change notification settings - Fork 38
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
Support for find_by_sql for SQL backends #121
Comments
I understand your issue, but that's something that we explicitly avoided from day 0. |
Also, I'm not sure if you're aware, but extending an existing repo/backend/etc. is very very easy if you use mixin: -module(my_store_mysql).
-author('[email protected]').
-behaviour(sumo_store).
-include_lib("mixer/include/mixer.hrl").
-mixin([
{sumo_store_mysql,
[ init/1
, create_schema/2
, persist/2
, delete/3
, delete_by/3
, delete_all/2
, find_all/2
, find_all/5
, find_by/3
, find_by/5
]}
]).
-export([find_by_sql/4]).
find_by_sql(SqlQuery, Values, DocName, State) ->
StatementName =
sumo_store_mysql:prepare(
DocName, list_to_atom(SqlQuery),
fun() -> SqlQuery end),
sumo_store_mysql:get_docs(DocName, StatementName, Values, State). NOTE: I just wrote that in this comment, it might not compile... but it will be close enough |
@elbrujohalcon Sounds good. I'll get started on |
@elbrujohalcon FYI, I've created sumo_db-sql-extras. It only supports find_by_sql for MySQL at this point, but it's a start. |
@spiegela I know… I'm watching it already :) |
There are a couple of SQL statement types that aren't supported by sumo_db, but are required for my project:
SELECT...JOIN
for many-to-many relationshipsSELECT...WHERE field IN ...
for a collection of many-to-many relationshipsRather than creating a bunch more SQL generation, which would take more planning, I thought we could implement find_by_sql for just the SQL backends. Other backends would implement the
find_by_sql/2
callback, but would running raise anot_implemented
error.Thoughts?
The text was updated successfully, but these errors were encountered: