
@niyarium has joined the channel

@popa.bogdanp A question about deta. I can’t reproduce the book example in https://deta.defn.io/ when I use ~>
. I get the following error
> (for/list ([b (in-entities conn (~> (from book #:as b)
(where (< b.published-on (date "1955-01-01")))
(order-by ([b.published-on #:desc]))))])
(book-title b))
stdin::17847-17893: where: expected more terms starting with q-expr
at: ()
within: (where (< b.published-on (date "1955-01-01")))
in: (where (< b.published-on (date "1955-01-01")))
location...:
stdin::17847
The problem seems to be with the where
call. I can get a where
call to work if I do this:
(define q (from book #:as b))
(where q (< b.published-on (date "1955-01-01")))
That works, producing the value
(query
"SELECT b.id, b.title, b.author, b.published_on FROM books AS b WHERE b.published_on < (DATE '1955-01-01')")
So the question is: has the code changed and the documentation is out of sync? Or am I missing something here? Thanks! (I’m using Racket 7.6 and I installed the library via raco pkg install deta
.)

@anything did you forget to install (and import) the threading
library (where ~>
is defined) by any chance?

Oh, I must have!

Here’s what I get now:
racket@model.rkt> (require threading)
racket@model.rkt> (for/list ([b (in-entities conn (~> (from book #:as b)
(where (< b.published-on (date "1955-01-01")))
(order-by ([b.published-on #:desc]))))])
(book-title b))
prepare: cannot prepare statement with virtual connection

So I guess I cannot use a virtual connection?

Unfortunately not. That’s one of the limitations of deta.

Got ya. Thanks. Thanks for writing the library! It is great.

That said, it might not be inherent although I don’t remember all the details off the top of my head. In my apps, I tend to pass around a connection pool rather than using virtual connections so I haven’t needed support for them, but if folks do, we might be able to get them to work.

My pleasure!

Further investigation: using unsafe-vector*-ref
in the generated code is another significant win (as I expected). Using predefined version of (vector 0)
and (vector 1)
is a win on Racket BC but not on Racket CS.

I have some more questions, if that’s okay. I’m not using PostgreSQL. I’m using SQLite. The following query seems invalid to SQLite.
racket@books.rkt> (~> (from book #:as b)
(where (< b.published-on (date "1955-01-01")))
(order-by ([b.published-on #:desc])))
(query
"SELECT b.id, b.title, b.author, b.published_on FROM books AS b WHERE b.published_on < (DATE '1955-01-01') ORDER BY b.published_on DESC")
racket@books.rkt>
The problem is with the (DATE ‘1995–01–01’). It would work if we change it to DATE(‘1995–01–01’), if that makes sense.

It should work as expected once you execute it on an SQLite connection.

also, @ecb10 if you have the generated Chez code that would be useful as comparison

The default printer assumes you’re using pg so that’s why you’re seeing pg syntax there, but it’s able to tell what adapter it should use based on the connection object you give it (eg. when you call in-entities
) and generate appropriate syntax for it.

Okay, but here’s what I get when I try: racket@books.rkt> (for/list ([b (in-entities conn (~> (from book #:as b)
(where (< b.published-on (date "1955-01-01")))
(order-by ([b.published-on #:desc]))))])
(book-title b))
prepare: near "'1955-01-01'": syntax error
error code: 1

Oh, sorry, I misread the query.

I’d say that’s a bug. If you open up a github issue, I can take a look later this week.

Sure thing. Should I add one or two? There’s an apparent problem with a delete query: racket@books.rkt> (delete (~> (from book #:as b)))
(query "DELETE FROM books AS b")
racket@books.rkt> (query-exec conn (delete (~> (from book #:as b))))
prepare: near "AS": syntax error
error code: 1

SQLite apparently doesn’t like the AS keyword in a delete query.

They added support for it in a point release, but I don’t remember exactly which one so you might just be running an old-ish version of sqlite3

What OS are you on?

That’s very possible. I’ll update my sqlite library. I’m running on Windows 10, Racket 7.6. (Will find out my sqlite version.)

select sqlite_version()
should return it

I made packages that distribute a recent version of SQLite3

Thanks! Mine is 3.13.0.

Ah, looks like I didn’t make one for Windows. Only mac and linux :smile:

:smile:

I must be using the one from the db package, no? (I can’t remember having installed a library myself.)

I don’t think the db package distributes an SQLite dll. Racket itself might since the module system depends on it.

I might have to update this DLL then. (I mean the one Racket itself includes.)

I’d assume it checks the usual place for dlls on Windows for it and then falls back to the version it comes packaged with. So if you just manually install it it might just work automatically. If not, someone here is bound to know how to update it.

I just updated it. Racket’s sqlite.dll is in lib/, that is the lib/ directory at the root of the Racket installation. I removed it from there and got the following error when I tried to [use] it: sqlite3_open: implementation not found; arguments: #"c:\sys\tolcom\current\daxko\daxko1\./storage.db" 6
This is evidence I was really using it. Then I put in the lib/ directory a new version and now the delete query works. So looks like just replacing the file with a newer one has done the job. Thanks! (I will only create an issue for the date() case then. )

also, are Idris strings lists? because the various string operations I see in this file are going to be slow.

The new DLL did not change my sqlite_version(), though. I expected it would change, but it’s still 3.13.0. Is that expected?

It depends. Where/how are you running the version query?

I’m running it with a program called SQLiteStudio.

I’m guessing that probably comes with its own SQLite3 dll :smile:

Hm, good point!

If you run (query-exec conn "select sqlite3_version()")
from a racket program I assume it’ll be different.

You seem to be right: racket@books.rkt> (query-list conn "select sqlite_version()")
'("3.31.1")
(Thanks so much!)

woahhh

since when did racket have pattern matching?

Jurassic

@marcelovmaciel has joined the channel

May 27, 2005, in this commit: https://github.com/racket/racket/commit/017d151d5929b49f01d83f9e41995b035cad23de#diff-fe9e17a78572881dd8fbe46d4d1a4d27

@popa.bogdanp, I need to print entities out in JSON. You probably have done this since you have done web development with deta
. But looking at the documentation I don’t see any obvious way. If I need to create a hasheq
myself, I will need the name of the fields of the entity. How could I get a list of the fields of the entity? (I mean, how would you do that?) (I would know what to do if I access the rows-result returned by query
, but I wonder if I’d be reinventing the wheel here. Thanks!)

That’s just the migration to SVN

It’s much older than that

And really that commit is a CVS artifact

Ohhh