Skip to content

Commit

Permalink
feat: added field varType to Variable type
Browse files Browse the repository at this point in the history
FossilOrigin-Name: 61de47150561fab4c9cc867657e0267628b29c468c8a6d3e8245c81c67d1abf2
  • Loading branch information
thindil committed Dec 25, 2023
1 parent e64dd51 commit f946f59
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/variables.nim
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ const
type
VariableName = LimitedString
## Used to store variables names in the database.
VariableValType = enum
## Used to set the type of variable's value
path, text, number
Variable* {.tableName: "variables".} = ref object of Model
## Data structure for the shell's environment variable
##
Expand All @@ -58,12 +61,46 @@ type
path: string
recursive: bool
value: string
varType: VariableValType
description: string

using
db: DbConn # Connection to the shell's database
arguments: UserInput # The string with arguments entered by the user for the command

proc dbType*(T: typedesc[VariableValType]): string {.raises: [], tags: [],
contractual.} =
## Set the type of field in the database
##
## * T - the type for which the field will be set
##
## Returns the type of the field in the database
body:
"TEXT"

proc dbValue*(val: VariableValType): DbValue {.raises: [], tags: [], contractual.} =
## Convert the type of the variable's value to database field
##
## * val - the value to convert
##
## Returns the converted val parameter
body:
dbValue(v = $val)

proc to*(dbVal: DbValue, T: typedesc[VariableValType]): T {.raises: [], tags: [],
contractual.} =
## Convert the value from the database to enumeration
##
## * dbVal - the value to convert
## * T - the type to which the value will be converted
##
## Returns the converted dbVal parameter
body:
try:
parseEnum[VariableValType](s = dbVal.s)
except:
text

proc buildQuery*(directory: DirectoryPath; fields: string = "";
where: string = ""): string {.sideEffect, raises: [], tags: [ReadDbEffect],
contractual.} =
Expand Down

0 comments on commit f946f59

Please sign in to comment.