mirror of
https://github.com/glimpse-app/server.git
synced 2025-04-02 10:52:45 -04:00
Switch to PostgeSQL... bye bye SQLite
This commit is contained in:
parent
adb834dac3
commit
18c4979bcf
8 changed files with 17 additions and 17 deletions
|
@ -1,6 +1,6 @@
|
|||
import norm/[model, sqlite]
|
||||
import norm/[model, postgres]
|
||||
import types/[users, files]
|
||||
# using sqlite as it makes setup faster
|
||||
# once project is stable enough this will switch to postgresql
|
||||
let db* = open("storage.db", "", "", "")
|
||||
let db* = open("0.0.0.0", "user", "postgres", "")
|
||||
db.createTables(newFile()) # file objects require a user object, thus a tables for both are created
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import std/strutils
|
||||
import jester
|
||||
import norm/[model, sqlite]
|
||||
import norm/[model, postgres]
|
||||
import checksums/sha3
|
||||
import ../types/users
|
||||
import ../[database, helpers]
|
||||
|
@ -46,7 +46,7 @@ proc createAuthenticationRoutes*() =
|
|||
|
||||
else:
|
||||
try:
|
||||
db.select(user, "username = ?", H"Username")
|
||||
db.select(user, """"User".username = $1""", H"Username")
|
||||
except NotFoundError:
|
||||
resp Http403, "Incorrect username or password.\n" # fails if username is wrong but mentions password to obfuscates if a user exists or not
|
||||
if user.password == $Sha3_512.secureHash($H"Password"):
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import std/[strutils, os, httpclient]
|
||||
import jester
|
||||
import norm/[model, sqlite]
|
||||
import norm/[model, postgres]
|
||||
import ../types/[users, files]
|
||||
import ../[database, helpers]
|
||||
|
||||
|
@ -61,7 +61,7 @@ proc createDeletionRoutes*() =
|
|||
|
||||
var file = newFile()
|
||||
try:
|
||||
db.select(file, "File.name = ?", H"Name")
|
||||
db.select(file, """"File".name = $1""", H"Name")
|
||||
except NotFoundError:
|
||||
resp Http404, "File does not exist.\n"
|
||||
|
||||
|
@ -83,7 +83,7 @@ proc createDeletionRoutes*() =
|
|||
|
||||
var listOfFiles = @[newFile()]
|
||||
try:
|
||||
db.select(listOfFiles, "File.owner = ?", user.id)
|
||||
db.select(listOfFiles, """"File".owner = $1""", user.id)
|
||||
except NotFoundError: # this error does not occur even if no files exist
|
||||
resp Http404, "Files do not exist.\n"
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import std/strutils
|
||||
import jester
|
||||
import norm/sqlite
|
||||
import norm/postgres
|
||||
import ../types/[users, files]
|
||||
import ../[database, helpers]
|
||||
|
||||
|
@ -20,7 +20,7 @@ proc createDownloadRoutes*() =
|
|||
|
||||
var file = newFile()
|
||||
try:
|
||||
db.select(file, "File.name = ?", H"Name")
|
||||
db.select(file, """"File".name = $1""", H"Name")
|
||||
except NotFoundError:
|
||||
resp Http404, "File does not exist.\n"
|
||||
|
||||
|
@ -38,7 +38,7 @@ proc createDownloadRoutes*() =
|
|||
|
||||
var listOfFiles = @[newFile()]
|
||||
try:
|
||||
db.select(listOfFiles, "File.owner = ?", user.id)
|
||||
db.select(listOfFiles, """"File".owner = $1""", user.id)
|
||||
except NotFoundError:
|
||||
resp Http404, "Files does not exist.\n"
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import std/[strutils, os]
|
||||
import jester
|
||||
import norm/sqlite
|
||||
import norm/postgres
|
||||
import ../types/[users, files]
|
||||
import ../[database, helpers]
|
||||
|
||||
|
@ -33,13 +33,13 @@ proc createUpdateRoutes*() =
|
|||
|
||||
var file = newFile()
|
||||
try:
|
||||
db.select(file, "File.name = ?", oldName)
|
||||
db.select(file, """"File".name = $1""", oldName)
|
||||
except NotFoundError:
|
||||
resp Http404, "File does not exist.\n"
|
||||
|
||||
block FileDoesNotExist:
|
||||
try:
|
||||
db.select(file, "File.name = ?", newName)
|
||||
db.select(file, """"File".name = $1""", newName)
|
||||
except NotFoundError:
|
||||
break FileDoesNotExist
|
||||
resp Http403, "File with that name already exists.\n"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import std/[strutils, os, json]
|
||||
import jester
|
||||
import norm/[model, sqlite]
|
||||
import norm/[model, postgres]
|
||||
import ../types/[users, files]
|
||||
import ../[database, helpers]
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import std/[strutils, os, json, asyncdispatch, httpclient]
|
||||
import jester
|
||||
import norm/[model, sqlite]
|
||||
import norm/[model, postgres]
|
||||
import checksums/sha3
|
||||
import ./types/[users, files]
|
||||
import ./[database, helpers]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import std/oids
|
||||
import norm/[model, sqlite]
|
||||
import norm/[model, postgres]
|
||||
import checksums/sha3
|
||||
|
||||
# define user object
|
||||
|
@ -13,7 +13,7 @@ type User* = ref object of Model
|
|||
# checks if the provided token exists in the database
|
||||
proc validToken*(db: DbConn, user: var User, token: string): bool =
|
||||
try:
|
||||
db.select(user, "token = ?", token)
|
||||
db.select(user, """"token" = $1""", token)
|
||||
return true
|
||||
except NotFoundError:
|
||||
return false
|
||||
|
|
Loading…
Add table
Reference in a new issue