Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import norm/[model, sqlite]
- import os
- type
- User* = ref object of Model
- user_id*: int
- firstname*: string
- lastname*: string
- username*: string
- Feed* = ref object of Model
- channel_id*: string
- playlist_id*: string
- video_id*: string
- name*: string
- url*: string
- UserFeed* = ref object of Model
- user*: User
- feed*: Feed
- var dbc: DbConn = nil
- func newUser*(user_id = 0, firstname = "", lastname = "", username = ""): User =
- return User(user_id: user_id, firstname: firstname, lastname: lastname, username: username)
- func newFeed*(channel_id = "", playlist_id = "", video_id = "", name = "", url = ""): Feed =
- return Feed(channel_id: channel_id, playlist_id: playlist_id, video_id: video_id, name: name, url: url)
- func newUserFeed*(user = newUser(), feed = newFeed()): UserFeed =
- return UserFeed(user: user, feed: feed)
- proc db(): DbConn =
- if dbc.isNil:
- putEnv("DB_HOST", getEnv("SQLITE_DBFILE"))
- dbc = getDb()
- return dbc
- proc createTables*() =
- db().createTables(newUser())
- db().createTables(newFeed())
- db().createTables(newUserFeed())
Advertisement
Add Comment
Please, Sign In to add comment