summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorJamesP <jlp765@gmail.com>2015-08-29 07:50:14 +1000
committerJamesP <jlp765@gmail.com>2015-08-29 07:50:14 +1000
commitda2d0845b8d4725888a58aaf0741d9227a380f3b (patch)
tree2f6baa6a400968e5386914a77ad823b82126724a /lib
parent1b47941b01c69ef2accf11622887de3a27d26c1c (diff)
downloadNim-da2d0845b8d4725888a58aaf0741d9227a380f3b.tar.gz
lib/impure/db_mysql add example code-block
Diffstat (limited to 'lib')
-rw-r--r--lib/impure/db_mysql.nim31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/impure/db_mysql.nim b/lib/impure/db_mysql.nim
index 197286f29..34537c7f7 100644
--- a/lib/impure/db_mysql.nim
+++ b/lib/impure/db_mysql.nim
@@ -9,6 +9,37 @@
 
 ## A higher level `mySQL`:idx: database wrapper. The same interface is 
 ## implemented for other databases too.
+##
+## Example:
+##
+## .. code-block:: Nim
+##
+##  import db_mysql, math
+##
+##  let theDb = open("localhost", "nim", "nim", "test")
+##
+##  theDb.exec(sql"Drop table if exists myTestTbl")
+##  theDb.exec(sql("create table myTestTbl (" &
+##      " Id    INT(11)     NOT NULL AUTO_INCREMENT PRIMARY KEY, " &
+##      " Name  VARCHAR(50) NOT NULL, " &
+##      " i     INT(11), " &
+##      " f     DECIMAL(18,10))"))
+##
+##  theDb.exec(sql"START TRANSACTION")
+##  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
+##
+##  let id = theDb.tryInsertId(sql"INSERT INTO myTestTbl (name,i,f) VALUES (?,?,?)",
+##          "Item#1001", 1001, sqrt(1001.0))
+##  echo "Inserted item: ", theDb.getValue(sql"SELECT name FROM myTestTbl WHERE id=?", id)
+##
+##  theDb.close()
+
 
 import strutils, mysql