-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit afefadf
Showing
4 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
poi | ||
test.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
poi - a bucket for everything | ||
|
||
## What is poi | ||
|
||
poi takes everything you threw at it and put them in a single bucket. | ||
|
||
Simplest storage for your data. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Package | ||
|
||
version = "0.1.0" | ||
author = "minamorl" | ||
description = "poi everything" | ||
license = "MIT" | ||
srcDir = "src" | ||
bin = @["poi"] | ||
|
||
|
||
# Dependencies | ||
|
||
requires "nim >= 2.0.2" | ||
requires "db_connector" | ||
requires "uuids" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import db_connector/db_sqlite | ||
import uuids | ||
import std/parseopt | ||
import std/os, std/strutils, std/strutils, std/sequtils | ||
|
||
|
||
let db = open("test.db", "", "", "") | ||
|
||
proc createTable(db: DBConn) = | ||
db.exec(sql""" | ||
CREATE TABLE IF NOT EXISTS documents ( | ||
id CHAR(36) PRIMARY KEY, | ||
content TEXT, | ||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP | ||
); | ||
""") | ||
|
||
proc insertDocument(db: DBConn, id: string, content: string) = | ||
db.exec(sql""" | ||
INSERT INTO documents (id, content) VALUES (?, ?); | ||
""", id, content) | ||
|
||
|
||
# create table if not exists | ||
db.createTable() | ||
|
||
|
||
proc insertMode() = | ||
let input = stdin.readAll() | ||
db.insertDocument($uuids.genUUID(), input) | ||
|
||
proc showMode() = | ||
echo "here" | ||
for row in db.rows(sql"SELECT id, content, created_at FROM documents"): | ||
echo row | ||
|
||
var p = initOptParser() | ||
while true: | ||
p.next() | ||
case p.kind | ||
of cmdEnd: break | ||
of cmdShortOption, cmdLongOption: | ||
case p.key | ||
of "show": | ||
showMode() | ||
of "insert": | ||
insertMode() | ||
else: | ||
echo "Unknown option: ", p.key | ||
of cmdArgument: | ||
echo "Unknown argument: ", p.val | ||
|