For SQLite, have a look at the doco 
[db_sqlite](https://nim-lang.org/docs/db_sqlite.html)
    
    
    import db_sqlite, math
    
    let theDb = open(":memory:",nil,nil,nil)
    #
    # now do create tables, insert data, select data, ....
    # using SQL (sqlite flavoured)
    #
    theDb.exec(sql"Drop table if exists myTestTbl")
    theDb.exec(sql("""create table myTestTbl (
         Id    INTEGER PRIMARY KEY,
         Name  VARCHAR(50) NOT NULL,
         i     INT(11),
         f     DECIMAL(18,10))"""))
    
    theDb.exec(sql"BEGIN")
    for i in 1..1000:
      theDb.exec(sql"INSERT INTO myTestTbl (name,i,f) VALUES (?,?,?)",
            "Item#" & $i, i, sqrt(i.float))
    theDb.exec(sql"COMMIT")
    
    for x in theDb.fastRows(sql"select * from myTestTbl"):
      echo x
    
    theDb.close()
    
    

Reply via email to