Skip to content

Commit

Permalink
Updated documentation; fixed d --> dlib typo
Browse files Browse the repository at this point in the history
  • Loading branch information
ayman-albaz committed Nov 17, 2022
1 parent 29907d4 commit 988f4e9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
28 changes: 11 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,42 @@ Opening/closing a database:
```Nim
import duckdb
# Open database and connection
var db = openDuckDB("test.duckdb")
var connection = db.connect()
# Close connection and database
connection.disconnect()
db.close()
# Open database and connection.
# Connection and database closed automatically with destructors
var dbConn = connect("mydb.db")
```


Opening/closing an in-memory database:
```Nim
import duckdb
# Open database and connection
# Connection and database closed automatically with destructors
var dbConn = connect()
```
Closing the database and the connection is done automatically though destructors

Executing commands and fetching a prepared statement
```Nim
connection.exec("CREATE TABLE integers(i INTEGER, j INTEGER);")
connection.exec("INSERT INTO integers VALUES (3, 4), (5, 6), (7, NULL);")
dbConn.exec("CREATE TABLE integers(i INTEGER, j INTEGER);")
dbConn.exec("INSERT INTO integers VALUES (3, 4), (5, 6), (7, NULL);")
var items: seq[seq[string]]
for item in connection.rows("SELECT * FROM integers WHERE i = ? or j = ?", 3, "6"):
for item in dbConn.rows("SELECT * FROM integers WHERE i = ? or j = ?", 3, "6"):
items.add(item)
assert items == @[@["3", "4"], @["5", "6"]]
```

Executing commands and fast inserting. Fast inserting is much faster than inserting in a loop.
```Nim
connection.exec("CREATE TABLE integers(i INTEGER, j INTEGER);")
connection.exec("INSERT INTO integers VALUES (3, 4), (5, 6), (7, NULL);")
connection.fastInsert(
dbConn.exec("CREATE TABLE integers(i INTEGER, j INTEGER);")
dbConn.exec("INSERT INTO integers VALUES (3, 4), (5, 6), (7, NULL);")
dbConn.fastInsert(
"integers",
@[
@["11", "NULL"]
],
)
var items: seq[seq[string]]
for item in connection.rows(
for item in dbConn.rows(
"""SELECT i, j, i + j
FROM integers"""
): items.add(item)
Expand Down
2 changes: 1 addition & 1 deletion src/duckdb/duckdb_wrapper.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ else:
const duckdbUrl = "https://github.com/duckdb/duckdb/releases/download/v0.5.1/libduckdb-osx-universal.zip"
const duckdbLib = "libduckdb.dylib"
when defined(Windows):
const duckdbLib = "libduckdb.d"
const duckdbLib = "libduckdb.dll"
when defined(cpu64):
const duckdbUrl = "https://github.com/duckdb/duckdb/releases/download/v0.5.1/libduckdb-windows-amd64.zip"
when defined(cpu32):
Expand Down

0 comments on commit 988f4e9

Please sign in to comment.