I need simple and handy database driver, didn't found what I wanted and decided 
to [experiment writing my own](https://github.com/al6x/nim/tree/main/postgres) 
:).

I think `pg_postgres` could be significantly improved if add:

  1. **Named parameters** for SQL (because for humans it's much easier to use 
associative mapping than counting and matching positions in array).
  2. **Type conversions** between SQL and Nim.



Both features easy to implement and they greatly simplify working with 
`pg_postgres`.

**Example** 
[source](https://github.com/al6x/nim/blob/main/postgres/examples/db_example.nim):
    
    
    ...
    
    # SQL with `:named` parameters instead of `?`
    db.exec("""
      insert into users ( name,  age)
      values            (:name, :age)
      """,
      (name: "Jim", age: 33)
    )
    
    ...
    
    # Conversion to objects, named or unnamed tuples
    let rows = db.get("""
      select name, age
      from users
      where age > :min_age
      """,
      (min_age: 10),
      tuple[name: string, age: int]
    )
    assert rows == @[(name: "Jim", age: 33)]
    
    
    Run

Reply via email to