Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intolerance of non-integer primary keys #11

Closed
otherjoel opened this issue Jan 6, 2020 · 2 comments
Closed

Intolerance of non-integer primary keys #11

otherjoel opened this issue Jan 6, 2020 · 2 comments
Labels
bug Something isn't working

Comments

@otherjoel
Copy link
Contributor

If I try to make a schema with a non-integer primary key, I get an error:

#lang racket/base

(require deta db)

(define-schema article
  ([page symbol/f #:primary-key]
   [date string/f]))

(define cache-conn (sqlite3-connect #:database "db.sqlite" #:mode 'create))

(create-table! cache-conn 'article)

(define a (make-article #:page 'my-article.html
                        #:date "2020-01-04"))

(insert-one! cache-conn a)

results in this error (on the insert-one! call):

set-article-page: contract violation
  expected: symbol?
  given: 1
  in: an and/c case of
      the 2nd argument of
      (->*
       (article? (and/c symbol? any/c))
       (boolean?)
       article?)
  contract from: (function set-article-page)
  blaming: /Users/joel/Documents/code/sandbox/deta/deta-1.rkt
   (assuming the contract is correct)
  at: /Users/joel/Documents/code/sandbox/deta/deta-1.rkt
@Bogdanp Bogdanp added the bug Something isn't working label Jan 6, 2020
@Bogdanp
Copy link
Owner

Bogdanp commented Jan 6, 2020

I think the fix here would be to make this code deal with cases where pk is already set to a value and, possibly, error when it isn't and its type is not an integer.

@otherjoel
Copy link
Contributor Author

Looks like the problem is SQLite-specific. Its dialect-supports-returning? is #f and its (dialect-last-id-query dialect) is always going to return the automatically-created rowid column regardless of what the primary key column is.

@Bogdanp Bogdanp closed this as completed in 7d4dbc2 Feb 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants