Guest User

Untitled

a guest
Jun 9th, 2023
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nim 1.12 KB | None | 0 0
  1. import norm/[model, sqlite]
  2. import os
  3.  
  4. type
  5.   User* = ref object of Model
  6.     user_id*: int
  7.     firstname*: string
  8.     lastname*: string
  9.     username*: string
  10.  
  11.   Feed* = ref object of Model
  12.     channel_id*: string
  13.     playlist_id*: string
  14.     video_id*: string
  15.     name*: string
  16.     url*: string
  17.  
  18.   UserFeed* = ref object of Model
  19.     user*: User
  20.     feed*: Feed
  21.  
  22. var dbc: DbConn = nil
  23.  
  24. func newUser*(user_id = 0, firstname = "", lastname = "", username = ""): User =
  25.   return User(user_id: user_id, firstname: firstname, lastname: lastname, username: username)
  26.  
  27. func newFeed*(channel_id = "", playlist_id = "", video_id = "", name = "", url = ""): Feed =
  28.   return Feed(channel_id: channel_id, playlist_id: playlist_id, video_id: video_id, name: name, url: url)
  29.  
  30. func newUserFeed*(user = newUser(), feed = newFeed()): UserFeed =
  31.   return UserFeed(user: user, feed: feed)
  32.  
  33. proc db(): DbConn =
  34.   if dbc.isNil:
  35.     putEnv("DB_HOST", getEnv("SQLITE_DBFILE"))
  36.     dbc = getDb()
  37.   return dbc
  38.  
  39. proc createTables*() =
  40.   db().createTables(newUser())
  41.   db().createTables(newFeed())
  42.   db().createTables(newUserFeed())
  43.  
  44.  
Advertisement
Add Comment
Please, Sign In to add comment