Skip to content

Commit

Permalink
poi
Browse files Browse the repository at this point in the history
  • Loading branch information
minamorl committed Apr 14, 2024
0 parents commit afefadf
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
poi
test.db
8 changes: 8 additions & 0 deletions README.md
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.

15 changes: 15 additions & 0 deletions poi.nimble
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"
52 changes: 52 additions & 0 deletions src/poi.nim
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

0 comments on commit afefadf

Please sign in to comment.