Code Monkey home page Code Monkey logo

debby's People

Contributors

treeform avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

debby's Issues

Postgres query SIGSEGV

  • if postgres returns an error for a query, the application crashes with a SIGSEGV
/Users/andrew.brower/src/debby/src/debby/postgres.nim(185) insertVec
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

proc query*(

doing some experimenting, I found adding echo repr res line before the result = getAllRows(res) line in query() will get the program to handle and display the correct error (but it does not echo, which is to be expected as it should be raising the error in prepareQuery)

/Users/andrew.brower/src/debby/src/debby/postgres.nim query
/Users/andrew.brower/src/Nim/lib/system.nim(170) prepareQuery
/Users/andrew.brower/src/debby/src/debby/postgres.nim dbError
Error: unhandled exception: Postgres: ERROR:  duplicate key value violates unique constraint "idx_name"
DETAIL:  Key (name)=({redacted}) already exists.
 [DbError]
  • The stacktrace appears strange, function lines don't match up with names. makes me suspect there's some sort of memory corruption going on.

[Bug] `debby/common.nim(141, 29) Error: undeclared field: 'id'`

Hi, I'm getting /home/chronos/.nimble/pkgs2/debby-0.2.0-6508726171aee3c8fce349d1de788d41aae39bec/debby/common.nim(141, 29) Error: undeclared field: 'id'

The code that triggered this was:

import debby/sqlite

let db = openDatabase(":memory:")

type
  DbObj = ref object of RootObj
    id*: int

  A = ref object of DbObj
    str: string

proc `$`(a: A): string = a.str

db.createTable(A)

db.insert(A(str: "wah!"))

var a = db.get(A, 1)

echo a

dump/parse hooks do not work when complex object is json serialized

import times
import debby/sqlite

proc sqlDumpHook*(v: DateTime): string =
  result = $v

proc sqlParseHook*(data: string, v: var DateTime) =
  v = parse(data, "yyyy-MM-dd'T'HH:mm:sszzz")

type
  Foo = ref object
    id: int
    created: DateTime
  Baa = ref object
    id: int
    foos: seq[Foo]

let db = openDatabase(":memory:")


db.createTable(Foo)
db.createTable(Baa)

# Works
let foo = Foo(created: now())
db.insert(foo)

# Does not work
let baa = Baa(foos: @[Foo(created: now())])
db.insert(baa)    

Error:

:!nim c -r debbydate202407053557.nim                                                                                                                     
Hint: used config file '/home/david/.choosenim/toolchains/nim-2.0.8/config/nim.cfg' [Conf]                                                               
Hint: used config file '/home/david/.choosenim/toolchains/nim-2.0.8/config/config.nims' [Conf]                                                           
Hint: used config file '/home/david/projects/nimPlayground/config.nims' [Conf]                                                                           
................................................................................................................                                         
/home/david/projects/nimPlayground/debbydate202407053557.nim(30, 3) template/generic instantiation of `insert` from here                                 
/home/david/.nimble/pkgs2/debby-0.6.1-65babc6498cc1ee64aa80af10d8716b3ee9e837d/debby/sqlite.nim(280, 13) template/generic instantiation of `insertInner` 
from here                                                                                                                                                
/home/david/.nimble/pkgs2/debby-0.6.1-65babc6498cc1ee64aa80af10d8716b3ee9e837d/debby/common.nim(184, 28) template/generic instantiation of `toArgument` f
rom here                                                                                                                                                 
/home/david/.nimble/pkgs2/debby-0.6.1-65babc6498cc1ee64aa80af10d8716b3ee9e837d/debby/common.nim(134, 21) template/generic instantiation of `toJson` from 
here                                                                                                                                                     
/home/david/.nimble/pkgs/jsony-1.1.5/jsony.nim(881, 11) template/generic instantiation of `dumpHook` from here                                           
/home/david/.nimble/pkgs/jsony-1.1.5/jsony.nim(775, 6) template/generic instantiation of `dumpHook` from here                                            
/home/david/.nimble/pkgs/jsony-1.1.5/jsony.nim(823, 6) template/generic instantiation of `dumpHook` from here                                            
/home/david/.nimble/pkgs/jsony-1.1.5/jsony.nim(823, 6) template/generic instantiation of `dumpHook` from here                                            
/home/david/.nimble/pkgs/jsony-1.1.5/jsony.nim(802, 8) Error: type mismatch                                                                              
Expression: dumpHook(s, v.zonedTimeFromTimeImpl)                                                                                                         
  [1] s: string                                                                                                                                          
  [2] v.zonedTimeFromTimeImpl: proc (x: Time): ZonedTime{.closure, gcsafe.}                                                                              
                                                                                                                                                         
Expected one of (first mismatch at [position]):                                                                                                          
[2] proc dumpHook(s: var string; v: JsonNode)                                                                                                            
[2] proc dumpHook(s: var string; v: RawJson)                                                                                                             
[2] proc dumpHook(s: var string; v: SomeFloat)                                                                                                           
[2] proc dumpHook(s: var string; v: bool)                                                                                                                
[2] proc dumpHook(s: var string; v: char)                                                                                                                
[2] proc dumpHook(s: var string; v: enum)                                                                                                                
[2] proc dumpHook(s: var string; v: int | int8 | int16 | int32 | int64)                                                                                  
[2] proc dumpHook(s: var string; v: object)                                                                                                              
[2] proc dumpHook(s: var string; v: ref)                                                                                                                 
[2] proc dumpHook(s: var string; v: string)                                                                                                              
[2] proc dumpHook(s: var string; v: tuple)                                                                                                               
[2] proc dumpHook(s: var string; v: uint | uint8 | uint16 | uint32 | uint64)                                                                             
[2] proc dumpHook[N, T](s: var string; v: array[N, T])                                                                                                   
[2] proc dumpHook[N, T](s: var string; v: array[N, t[T]])                                                                                                
[2] proc dumpHook[T: distinct](s: var string; v: T)                                                                                                      
[2] proc dumpHook[T](s: var string; v: Option[T])                                                                                                        
[2] proc dumpHook[T](s: var string; v: SomeSet[T] | set[T])                                                                                              
[2] proc dumpHook[T](s: var string; v: seq[T])                                                                                                           
                                                                                                                                                         
                                                                                                                                                         
shell returned 1                                                        

Edit: or it might be some issue with DateTime (that i do not understand fully tbh)

prepareQuery() fails if a string contains `?`

I have a function to do a bulk insert that was previously working on waterpark:

using debby/postgres, this query works most of the time, but fails with a dbError if one of the string fields has a ? in it. "Number of arguments and number of ? in query does not match"

proc bulkInsertTypeIDs*(db: Db, typeIDs: seq[TypeID]) =
  var rows: seq[string] = @[]
  for t in typeIDs:
    rows.add(fmt"""
    (
      '{t.typeID}',
      '{t.nameEN.escapeString.}',
      '{t.published}'
    )
    """)
  let copyStr = fmt"""
    INSERT INTO sde_type_ids (
      type_id,
      name_en,
      published
      ) VALUES 
    {rows.join(",\n")}
    ;
  """
  db.query(copyStr)

[Feature Request] Alternative Table Name

Greetings. I enjoy very much using your library and it would be very interesting to be able to set a different name for the table, instead of the name of the object.

An implementation would be something like that:

type
  User* = ref object
    id*: int
    name*: string

db.createTable(User, "alternative_name")

Moreover I think this would be very useful because as of now, you cannot name your object 'User' since it is a reserved keyword in SQL.

[Feature Request] Field Constraints

Hey there, I'm wondering if it'd be feasible to add something constraints to Debby (likely as pragmas as that makes the most sense to me), to allow for fields in tables to be set as unique for example, which would be useful for unique user IDs.

This would be perfectly suited for my usecase, as I am working on a chat app, and I'd imagine others may want this too.

Example syntax would be

type Profile = ref object
  id: int
  uid {.constraints: unique.}: int

or just {.unique.}

Relations Support

Hello!

Cool project, I think it has a lot of potential and would love to use it. One thing that I would like to see is supporting the "R" part in ORM. I don't see debby supporting anything with relations, like

type Auto = ref object
  id: int
  make: string
  model: string
  year: int

type Dealer = ref object
  id: int
  autos: seq[Auto]

Maybe you'd have a custom type instead of seq but this is a feature many ORMs support. Debby is still cool as an "object mapper" but this is my wish list :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.