--
You received this message because you are subscribed to a topic in the Google Groups "elixir-ecto" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elixir-ecto/8MOkRFAdLZc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elixir-ecto+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/elixir-ecto/98c2f8fe-7d59-4e7d-8d77-b46793f23dban%40googlegroups.com.
After looking into other sigil implementation e.g Phoenix ~p then I believe the best I would be able to do is generating if clause for the vars that are used in a interpolation, that would give us runtime validation, which I think it good enough for a POC. But I’m still interested if anyone know if we could archive compile-time validation for the sigil.Technically we could create a lock file with all the information of the columns, but not sure if there would be any road blocks.Hey there,I've been experimenting with creating an Ecto SQL sigil, and I'm wondering if it's possible to validate interpolation in a macro sigil.```id = 1~SQL"select * from users where id = #{id}"```FYI, getting the information to validate column types is straightforward as the SQL standard has the information schema. For any non-compliant RDBMS, the adapter structure would make it straightforward to implement specific queries.
--
You received this message because you are subscribed to a topic in the Google Groups "elixir-ecto" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elixir-ecto/8MOkRFAdLZc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elixir-ecto...@googlegroups.com.
You received this message because you are subscribed to the Google Groups "elixir-ecto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-ecto...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/elixir-ecto/b7b8953c-0567-4f68-89df-f9c06799cc54n%40googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/elixir-ecto/696cd009-7c86-4c61-8a81-794dd25e3148n%40googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/elixir-ecto/8d345653-9ea6-41a2-bd99-526806f8a87dn%40googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/elixir-ecto/bd97b26e-3916-48ee-b4eb-e2167a50b6d7n%40googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/elixir-ecto/d71a63b5-55d2-484d-a561-c3b054c60bbcn%40googlegroups.com.
➜ sql git:(main) ✗ mix sql.bench
Compiling 1 file (.ex)
Generated sql app
Operating System: macOS
CPU Information: Apple M1 Max
Number of Available Cores: 10
Available memory: 64 GB
Elixir 1.18.3
Erlang 27.3.3
JIT enabled: true
Benchmark suite executing with the following configuration:
warmup: 2 s
time: 10 s
memory time: 2 s
reduction time: 0 ns
parallel: 1
inputs: none specified
Estimated total run time: 56 s
Benchmarking ecto ...
Benchmarking inspect ...
Benchmarking to_sql ...
Benchmarking to_string ...
Calculating statistics...
Formatting results...
Name ips average deviation median 99th %
to_string 2.10 K 0.48 ms ±5.77% 0.47 ms 0.59 ms
to_sql 1.94 K 0.52 ms ±15.55% 0.50 ms 0.78 ms
inspect 0.21 K 4.76 ms ±11.22% 4.64 ms 6.37 ms
ecto 0.00678 K 147.55 ms ±1.98% 147.55 ms 157.09 ms
Comparison:
to_string 2.10 K
to_sql 1.94 K - 1.09x slower +0.0406 ms
inspect 0.21 K - 10.01x slower +4.28 ms
ecto 0.00678 K - 310.47x slower +147.07 ms
Memory usage statistics:
Name Memory usage
to_string 1.30 MB
to_sql 1.53 MB - 1.18x memory usage +0.23 MB
inspect 7.63 MB - 5.89x memory usage +6.33 MB
ecto 202.87 MB - 156.62x memory usage +201.57 MB
**All measurements for memory usage were the same**
➜ sql git:(main) ✗ mix deps.get && mix sql.gen.test ../sqltest/standards/2016 && mix test
Resolving Hex dependencies...
Resolution completed in 0.024s
Unchanged:
benchee 1.3.1
db_connection 2.7.0
decimal 2.3.0
deep_merge 1.0.0
earmark_parser 1.4.43
ecto 3.12.5
ecto_sql 3.12.1
ex_doc 0.37.2
makeup 1.2.1
makeup_elixir 1.0.1
makeup_erlang 1.0.2
nimble_parsec 1.4.2
postgrex 0.20.0
statistex 1.0.0
telemetry 1.3.0
yamerl 0.10.0
All dependencies are up to date
Compiling 4 files (.ex)
Generated sql app
* creating test/conformance/e_test.exs
* creating test/conformance/f_test.exs
* creating test/conformance/s_test.exs
* creating test/conformance/t_test.exs
Compiling 4 files (.ex)
Generated sql app
Running ExUnit with seed: 856209, max_cases: 20
............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
Finished in 1.9 seconds (1.9s async, 0.00s sync)
956 tests, 0 failures
➜ sql git:(main) ✗ mix deps.get && mix sql.gen.test ../sqltest/standards/2016 && mix test
Resolving Hex dependencies...
Resolution completed in 0.025s
Unchanged:
benchee 1.3.1
db_connection 2.7.0
decimal 2.3.0
deep_merge 1.0.0
earmark_parser 1.4.43
ecto 3.12.5
ecto_sql 3.12.1
ex_doc 0.37.2
makeup 1.2.1
makeup_elixir 1.0.1
makeup_erlang 1.0.2
nimble_parsec 1.4.2
postgrex 0.20.0
statistex 1.0.0
telemetry 1.3.0
yamerl 0.10.0
All dependencies are up to date
* creating test/conformance/e_test.exs
* creating test/conformance/f_test.exs
* creating test/conformance/s_test.exs
* creating test/conformance/t_test.exs
Running ExUnit with seed: 149448, max_cases: 20
.................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
Finished in 11.5 seconds (11.5s async, 0.00s sync)
961 tests, 0 failures
➜ sql git:(main) ✗ mix sql.bench
Operating System: macOS
CPU Information: Apple M1 Max
Number of Available Cores: 10
Available memory: 64 GB
Elixir 1.18.3
Erlang 27.3.3
JIT enabled: true
Benchmark suite executing with the following configuration:
warmup: 2 s
time: 5 s
memory time: 2 s
reduction time: 2 s
parallel: 1
inputs: 1..100_000
Estimated total run time: 1 min 50 s
Benchmarking comptime ecto with input 1..100_000 ...
Benchmarking comptime inspect with input 1..100_000 ...
Benchmarking comptime to_sql with input 1..100_000 ...
Benchmarking comptime to_string with input 1..100_000 ...
Benchmarking lex with input 1..100_000 ...
Benchmarking parse with input 1..100_000 ...
Benchmarking runtime ecto with input 1..100_000 ...
Benchmarking runtime inspect with input 1..100_000 ...
Benchmarking runtime to_sql with input 1..100_000 ...
Benchmarking runtime to_string with input 1..100_000 ...
Calculating statistics...
Formatting results...
##### With input 1..100_000 #####
Name ips average deviation median 99th %
comptime to_sql 22.05 M 45.36 ns ±31872.80% 42 ns 42 ns
comptime to_string 21.82 M 45.84 ns ±40289.89% 42 ns 42 ns
runtime to_string 21.72 M 46.04 ns ±41584.01% 42 ns 42 ns
runtime to_sql 20.17 M 49.59 ns ±54043.19% 42 ns 42 ns
comptime inspect 4.06 M 246.19 ns ±11260.76% 167 ns 333 ns
runtime inspect 3.87 M 258.43 ns ±10897.27% 167 ns 333 ns
parse 1.74 M 573.30 ns ±2688.99% 541 ns 667 ns
lex 0.23 M 4294.48 ns ±198.77% 4167 ns 4958 ns
runtime ecto 0.195 M 5139.65 ns ±199.40% 4958 ns 7250 ns
comptime ecto 0.193 M 5186.87 ns ±108.00% 4667 ns 16959 ns
Comparison:
comptime to_sql 22.05 M
comptime to_string 21.82 M - 1.01x slower +0.48 ns
runtime to_string 21.72 M - 1.01x slower +0.68 ns
runtime to_sql 20.17 M - 1.09x slower +4.23 ns
comptime inspect 4.06 M - 5.43x slower +200.84 ns
runtime inspect 3.87 M - 5.70x slower +213.07 ns
parse 1.74 M - 12.64x slower +527.95 ns
lex 0.23 M - 94.68x slower +4249.13 ns
runtime ecto 0.195 M - 113.32x slower +5094.30 ns
comptime ecto 0.193 M - 114.36x slower +5141.51 ns
Memory usage statistics:
Name Memory usage
comptime to_sql 24 B
comptime to_string 0 B - 0.00x memory usage -24 B
runtime to_string 0 B - 0.00x memory usage -24 B
runtime to_sql 24 B - 1.00x memory usage +0 B
comptime inspect 344 B - 14.33x memory usage +320 B
runtime inspect 344 B - 14.33x memory usage +320 B
parse 2432 B - 101.33x memory usage +2408 B
lex 11976 B - 499.00x memory usage +11952 B
runtime ecto 21336 B - 889.00x memory usage +21312 B
comptime ecto 18848 B - 785.33x memory usage +18824 B
**All measurements for memory usage were the same**
Reduction count statistics:
Name Reduction count
comptime to_sql 2
comptime to_string 7 - 3.50x reduction count +5
runtime to_string 7 - 3.50x reduction count +5
runtime to_sql 2 - 1.00x reduction count +0
comptime inspect 28 - 14.00x reduction count +26
runtime inspect 28 - 14.00x reduction count +26
parse 210 - 105.00x reduction count +208
lex 154 - 77.00x reduction count +152
runtime ecto 1193 - 596.50x reduction count +1191
comptime ecto 1132 - 566.00x reduction count +1130
**All measurements for reduction count were the same**