Skip to content

Commit

Permalink
refactor: some code cleanup
Browse files Browse the repository at this point in the history
FossilOrigin-Name: 7224707ed9bf307b9b42db0bb9041019170ad25d956ee9ab7969937b3baad27f
  • Loading branch information
thindil committed Nov 26, 2023
1 parent 3461bb9 commit d5aa7fa
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/db.nim
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# Standard library imports
import std/[os, strutils, terminal]
# External modules imports
import contracts
import contracts, nimalyzer
import norm/sqlite
# Internal imports
import aliases, constants, commandslist, completion, directorypath, help,
Expand All @@ -39,7 +39,11 @@ const
dbCommands*: seq[string] = @["optimize"]
## The list of available subcommands for command alias

proc closeDb*(returnCode: ResultCode; db: DbConn) {.sideEffect, raises: [],
using
db: DbConn # Connection to the shell's database
arguments: UserInput # The string with arguments entered by the user for the command

proc closeDb*(returnCode: ResultCode; db) {.sideEffect, raises: [],
tags: [DbEffect, WriteIOEffect, ReadEnvEffect, TimeEffect, RootEffect],
contractual.} =
## Close the shell database and quit from the program with the selected return code
Expand Down Expand Up @@ -233,7 +237,7 @@ proc startDb*(dbPath: DirectoryPath): DbConn {.sideEffect, raises: [], tags: [
e = getCurrentException())
return nil

proc optimizeDb*(arguments: UserInput; db: DbConn): ResultCode {.sideEffect,
proc optimizeDb*(arguments; db): ResultCode {.sideEffect,
raises: [], tags: [WriteDbEffect, ReadDbEffect, WriteIOEffect, ReadIOEffect,
RootEffect], contractual.} =
## Optimize the shell's database
Expand All @@ -254,9 +258,8 @@ proc optimizeDb*(arguments: UserInput; db: DbConn): ResultCode {.sideEffect,
e = getCurrentException())
return QuitSuccess.ResultCode

proc initDb*(db: DbConn; commands: ref CommandsList) {.sideEffect, raises: [],
tags: [ReadDbEffect, WriteIOEffect, ReadEnvEffect, TimeEffect,
WriteDbEffect,
proc initDb*(db; commands: ref CommandsList) {.sideEffect, raises: [], tags: [
ReadDbEffect, WriteIOEffect, ReadEnvEffect, TimeEffect, WriteDbEffect,
ReadIOEffect, RootEffect], contractual.} =
## Initialize the shell's database. Set database's related commands
##
Expand All @@ -268,10 +271,10 @@ proc initDb*(db: DbConn; commands: ref CommandsList) {.sideEffect, raises: [],
db != nil
body:
# Add commands related to the shell's aliases
proc dbCommand(arguments: UserInput; db: DbConn;
list: CommandLists): ResultCode {.raises: [], tags: [WriteIOEffect,
WriteDbEffect, TimeEffect, ReadDbEffect, ReadIOEffect, ReadEnvEffect,
RootEffect], contractual.} =
proc dbCommand(arguments; db; list: CommandLists): ResultCode {.raises: [],
tags: [WriteIOEffect, WriteDbEffect, TimeEffect, ReadDbEffect,
ReadIOEffect, ReadEnvEffect, RootEffect], ruleOff: "paramsUsed",
contractual.} =
## The code of the shell's command "nishdb" and its subcommands
##
## * arguments - the arguments entered by the user for the command
Expand Down

0 comments on commit d5aa7fa

Please sign in to comment.