Araq / ormin

Ormin -- An ORM for Nim.
MIT License
153 stars 18 forks source link

ormin/queries: prepare the statement once on query execution #40

Closed alaviss closed 4 years ago

alaviss commented 4 years ago

This prevents ormin from running prepareStmt before the db is opened.

Fixes #21

Araq commented 4 years ago

Huh? That optimization is important. I thought about populating a proc prepareStatement(ctx) and to expose the state rather than relying on globals. This way threading would be simpler.

alaviss commented 4 years ago

As a stop-gap measure, I'm switching to using a global + once to keep the optimization, while making sure that the statements won't be prepared before a db connection is established.

alaviss commented 4 years ago

I thought about populating a proc prepareStatement(ctx) and to expose the state rather than relying on globals. This way threading would be simpler.

Quoting discussion on IRC:

16:49:08 \<leorize> Araq: so what should I do about Araq/ormin#40? 16:50:41 \<leorize> having a ctx sounds fine to me, but how would it match with the current semantics? 16:51:07 \<Araq> not sure but the state must be exposed somehow 16:51:25 \<Araq> this design problem keeps Ormin from reaching v1 IMO 16:52:08 \<Araq> maybe the only good solution is setContext() 16:55:12 \<leorize> how would that work? 16:55:58 \<leorize> or are you planning to make queries an imported module instead of being included? 16:57:18 \<leorize> if it's included then we can just have a ctx global and a init() proc that should run before any queries are made