An asynchronous query builder library inspired by Laravel/PHP and Orator/Python for Nim
import asyncdispatch
import allographer/connection
import allographer/query_builder
let maxConnections = 95
let timeout = 30
let rdb = dbOpen(PostgreSql, "database", "user", "password" "localhost", 5432, maxConnections, timeout)
# also available
# let rdb = dbOpen(Sqlite3, "/path/to/db/sqlite3.db", maxConnections=maxConnections, timeout=timeout)
# let rdb = dbOpen(MySQL, "database", "user", "password" "localhost", 3306, maxConnections, timeout)
# let rdb = dbOpen(MariaDB, "database", "user", "password" "localhost", 3306, maxConnections, timeout)
proc main(){.async.} =
let result = await rdb
.table("users")
.select("id", "email", "name")
.limit(5)
.offset(10)
.get()
echo result
waitFor main()
>> SELECT id, email, name FROM users LIMIT 5 OFFSET 10
>> @[
{"id":11,"email":"user11@gmail.com","name":"user11"},
{"id":12,"email":"user12@gmail.com","name":"user12"},
{"id":13,"email":"user13@gmail.com","name":"user13"},
{"id":14,"email":"user14@gmail.com","name":"user14"},
{"id":15,"email":"user15@gmail.com","name":"user15"}
]
import allographer/schema_builder
rdb.schema([
table("auth", [
Column().increments("id"),
Column().string("name").nullable(),
Column().timestamp("created_at").default()
]),
table("users", [
Column().increments("id"),
Column().string("name"),
Column().foreign("auth_id").reference("id").on("auth").onDelete(SET_NULL)
])
])
>> CREATE TABLE auth (
id INT NOT NULL PRIMARY KEY,
name VARCHAR,
created_at DATETIME DEFAULT (NOW())
)
>> CREATE TABLE users (
id INT NOT NULL PRIMARY KEY,
name VARCHAR NOT NULL,
auth_id INT,
FOREIGN KEY(auth_id) REFERENCES auth(id) ON DELETE SET NULL
)
rdb.alter(
table("users", [
add().string("email").unique().default(""),
delete("name")
])
)
>> ALTER TABLE "users" ADD COLUMN `email` UNIQUE DEFAULT "" CHECK (length(`email`) <= 255)
>> ALTER TABLE "users" DROP `name`
nimble install allographer
First of all, add nim binary path
export PATH=$PATH:~/.nimble/bin
After install allographer, "dbtool" command is going to be available.
Database connection should be definded as singleton variable.
database.nim
import allographer/connection
let rdb* = dbOpen(PostgreSql, "database", "user", "password" "localhost", 5432, maxConnections, timeout)
# you can create connection for multiple database at same time.
let sqliteRdb* = dbOpen(Sqlite3, "/path/to/db/sqlite3.db", maxConnections=maxConnections, timeout=timeout)
let mysqlRdb* = dbOpen(MySQL, "database", "user", "password" "localhost", 3306, maxConnections, timeout)
let mariaRdb* = dbOpen(MariaDB, "database", "user", "password" "localhost", 3306, maxConnections, timeout)
Then, call connection when you run query.
run_sql.nim
import asyncdispatch
import allographer/query_builder
from database import rdb
proc main(){.async.}=
echo await rdb.table("users").get()
waitFor main()
Please set args in dbOpen()
proc dbOpen*(driver:Driver, database:string="", user:string="", password:string="",
host: string="", port=0, maxConnections=1, timeout=30,
shouldDisplayLog=false, shouldOutputLogFile=false, logDir=""):Rdb
Please create this branch name when you will create a new pull request.
Branch | Description |
---|---|
feature/*** | New feature branch |
hotfix/*** | Bug fix branch |
chore/*** | Chore work or maintenance |
This naming rule automatically labels the pull request.
Nimrod(已改名为 Nim)是一种静态类型的编译系统编程语言。它结合了 Python、Ada和Modula等成熟语言的成功理念。 高效的 Nim生成不依赖于虚拟机的本机无依赖可执行文件,这些可执行文件很小并且允许重新分配。 Nim编译器和生成的可执行文件支持所有主要平台,例如Windows,Linux,BSD和macOS。 在C ++和Rust的启发下,Nim的内存管理是确定性的,并且可以使用
nim-asciitables simple terminal ascii tables for nim DEPRECATION project is deprecated in favor for nim-terminaltables How to use asciitables has a very simple api setHeaders to set column names addRo
nim-terminaltables terminal tables for nim API API docs available hereterminaltables has a very small API newUnicodeTable uses unicodeStyle newAsciiTable uses asciiStyle Table style is configurable us
Dashing is a library to quickly create terminal-based dashboards in Nim. Dashing provides high-level components: vertical and horizontal charts, gauges, log panes, text windows and screen splitting. I
Gatabase Works with ARC, ORC, --panics:on, --experimental:strictFuncs. Use Gatabase is designed as 1 simplified Strong Static Typed Connection-Pooling Compile-Time SQL DSL Sugar. Nim mimics SQL. ~1000
libssh2.nim Nim wrapper for libssh2 For document please refer to libssh2 website Requirements In order to use this wrapper, libssh2 must installed on your system: Mac OSX:$ port install libssh2 Ubuntu