mini_sql
mini_sql copied to clipboard
encode param as pg array
Hmmm ... maybe we support:
conn.auto_encode_arrays!
Then you would not need .array calls if you are careful with your usage.
if we introduce conn.auto_encode_arrays! then it will be necessary to rewrite the old sql
with conn.array developers can create arrays only in the necessary places
conn.query("select * from products where supplier_id = ? and category_ids && ?", 127, conn.array([12, 24, 67]))
conn.array need not only in prepared connection
understood, my thinking is that conn.auto_encode_arrays! would be something you enable if you are just about to start a brand new project and saves you ceremony.
Is there any downside to doing this 100% automatically, if we see an Array in the param we just use encode array? What can break with a change like that?
ANY/SOME (array) support only postgres
postgres on planning step, rewrites IN to = ANY
explain analyze select id from suppliers where id in (12, 24, 67);
Bitmap Heap Scan on suppliers (cost=2.97..6.57 rows=3 width=4)
-> Bitmap Index Scan on suppliers_pkey (cost=0.00..2.96 rows=3 width=0)
Index Cond: (id = ANY ('{12,24,67}'::bigint[]))
i think on pg connection good idea automatically use encode array, but then, we won't be able to use IN, this is a breaking change
Hello @SamSaffron, I added array_encoder option for pg connection, query code more readable and unified in project (no ambiguity IN or ANY)
Rails is doing similar work https://github.com/rails/rails/pull/49388