Skip to content

Commit

Permalink
Refactored [_] generics
Browse files Browse the repository at this point in the history
These are (currently) no longer supported by nim devel.
For reference, see:
- nim-lang/Nim#21435
- nim-lang/Nim#21192

It is likely that this behaviour will stay.
Either way, there is no particular need to stick with [_],
thus we shall proactively remove it, just to be safe.
  • Loading branch information
PhilippMDoerner committed Feb 25, 2023
1 parent 4479240 commit 18b0f19
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/norm/private/postgres/dbtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ func dbValue*[T: Model](val: Option[T]): DbValue =
else:
dbValue(nil)

func dbValue*[_](val: StringOfCap[_]): DbValue = dbValue(string(val))
func dbValue*[T](val: StringOfCap[T]): DbValue = dbValue(string(val))

func dbValue*[_](val: PaddedStringOfCap[_]): DbValue = dbValue(string(val))
func dbValue*[T](val: PaddedStringOfCap[T]): DbValue = dbValue(string(val))


# Converter funcs from ``DbValue`` instances to Nim types:
Expand All @@ -67,9 +67,9 @@ func to*(dbVal; T: typedesc[SomeFloat]): T = dbVal.f.T

func to*(dbVal; T: typedesc[string]): T = dbVal.s

func to*[_](dbVal; T: typedesc[StringOfCap[_]]): T = dbVal.o.value.T
func to*[U](dbVal; T: typedesc[StringOfCap[U]]): T = dbVal.o.value.T

func to*[_](dbVal; T: typedesc[PaddedStringOfCap[_]]): T = dbVal.o.value.T
func to*[U](dbVal; T: typedesc[PaddedStringOfCap[U]]): T = dbVal.o.value.T

func to*(dbVal; T: typedesc[bool]): T = dbVal.b

Expand Down
8 changes: 4 additions & 4 deletions src/norm/private/sqlite/dbtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ func dbValue*(val: DateTime): DbValue = dbValue(val.toTime().toUnixFloat())

func dbValue*[T: Model](val: T): DbValue = dbValue(val.id)

func dbValue*[_](val: StringOfCap[_]): DbValue = dbValue(string(val))
func dbValue*[T](val: StringOfCap[T]): DbValue = dbValue(string(val))

func dbValue*[_](val: PaddedStringOfCap[_]): DbValue = dbValue(string(val))
func dbValue*[T](val: PaddedStringOfCap[T]): DbValue = dbValue(string(val))

func dbValue*(val: Option[bool]): DbValue =
if val.isSome:
Expand Down Expand Up @@ -90,9 +90,9 @@ func to*(dbVal; T: typedesc[DbBlob]): T = dbVal.b

proc to*(dbVal; T: typedesc[DateTime]): T = utc dbVal.f.fromUnixFloat()

func to*[_](dbVal; T: typedesc[StringOfCap[_]]): T = dbVal.s.T
func to*[U](dbVal; T: typedesc[StringOfCap[U]]): T = dbVal.s.T

func to*[_](dbVal; T: typedesc[PaddedStringOfCap[_]]): T = dbVal.s.T
func to*[U](dbVal; T: typedesc[PaddedStringOfCap[U]]): T = dbVal.s.T

func to*(dbVal; T: typedesc[Model]): T =
## This is never called and exists only to please the compiler.
Expand Down
8 changes: 4 additions & 4 deletions src/norm/types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ func newStringOfCap*[C: static[int]](val = ""): StringOfCap[C] =
func newPaddedStringOfCap*[C: static[int]](val = ""): PaddedStringOfCap[C] =
PaddedStringOfCap[C](val.alignLeft(C))

func `==`*[_](x, y: StringOfCap[_]): bool =
func `==`*[T](x, y: StringOfCap[T]): bool =
string(x) == string(y)

func `==`*[_](x, y: PaddedStringOfCap[_]): bool =
func `==`*[T](x, y: PaddedStringOfCap[T]): bool =
string(x) == string(y)

func `$`*[_](s: StringOfCap[_]): string =
func `$`*[T](s: StringOfCap[T]): string =
string(s)

func `$`*[_](s: PaddedStringOfCap[_]): string =
func `$`*[T](s: PaddedStringOfCap[T]): string =
string(s)

0 comments on commit 18b0f19

Please sign in to comment.