artemeff / eql

Erlang with SQL or not
MIT License
116 stars 18 forks source link

Generating modules #12

Closed tsloughter closed 5 years ago

tsloughter commented 6 years ago

I keep going back and forth with myself on whether it is worth creating modules with a function per query. So I thought I'd just propose it here to see if there is interest and if there is interest whether it should be in eql or a separate library.

I don't think performance is really a reason. Though since they would mostly be literals it does gain performance by not having to be copied when used, as of Erlang 20. But pretty tiny gain compared to the rest of the time spent sending a query to a db and decoding the results.

The main reason I've been interested in it is static analysis (xref and dialyzer will catch when I'm using a query that doesn't exist, including if there are named parameters that need to be in the arguments) and simplifying runtime startup.

vladimir-vg commented 6 years ago

That would require to add some hooks into rebar3, to make it properly (re)generate modules, right?

tsloughter commented 6 years ago

Yea, I guess it would either be a rebar3 provider added as a module to eql or a separate project that is a plugin depending on eql.

tsloughter commented 6 years ago

Oh, should mention that it could be done without a plugin and at runtime easily with merl. But that doesn't include the gains related to dialyzer and xref that building beams in a plugin and writing to disk does.

vladimir-vg commented 6 years ago

What about having both options? Generated modules (by rebar) by default, but still have an old API for people who for some reasons don't use rebar or don't want to make building process more complicated.

tsloughter commented 6 years ago

Yea, definitely would not want it to be the only option.

tsloughter commented 5 years ago

Closing this. The appropriate way forward would be persistent_term in OTP 21.2+. I'll eventually make a PR for that.

Importantly it will be optional the same as ets is since it should only be used in cases that queries are read in and never updated/replaced. I'd suspect that is rare for anyone to do who uses eql but who knows.