juancarlospaco / nim-gatabase

Connection-Pooling Compile-Time ORM for Nim
https://juancarlospaco.github.io/nim-gatabase
MIT License
120 stars 5 forks source link

Example code can't compile #11

Open cpunion opened 2 years ago

cpunion commented 2 years ago

Test code below copied from README.md :

import db_sqlite, gatabase

let db = open(":memory:", "", "", "")
db.exec(sql"""
  create table if not exists person(
    id      integer     primary key,
    name    varchar(9)  not null unique,
    active  bool        not null default true,
    rank    float       not null default 0.0
  ); """)

exec [42, "Pepe", true, 9.6]:
  insertinto "person"
  values 4

let row = [].getRow:
  select '*'
  `from` "person"

echo row

It compiles fail:

$ nim c -r test.nim
test.nim(12, 11) Error: type mismatch: got 'string' for '"Pepe"' but expected 'int literal(42)'

$ nim -v
Nim Compiler Version 1.6.8 [MacOSX: arm64]
Compiled at 2022-09-27
Copyright (c) 2006-2021 by Andreas Rumpf

active boot switches: -d:release -d:nimUseLinenoise
cpunion commented 2 years ago

Splitted template exec to two definitions:

template exec*(args: varargs[string, `$`]; inner: untyped)

template exec*(args: seq[string]; inner: untyped)

It works.

juancarlospaco commented 2 years ago

Pull Request welcome.

cpunion commented 2 years ago

@juancarlospaco So what is the reason? Does the Nim compiler has a break change?

I'm not sure it's a good way, too many template methods need to change.

image
juancarlospaco commented 2 years ago

I am kinda waiting for Nim 2.0 to re-check everything one-by-one, because it may bring improvements in multiple places, but if you need it urgently then feel free to send Pull Request.