niyarium
2020-3-16 12:48:56

@niyarium has joined the channel


anything
2020-3-16 18:43:23

@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.)


popa.bogdanp
2020-3-16 18:51:04

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


anything
2020-3-16 18:51:26

Oh, I must have!


anything
2020-3-16 18:55:31

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


anything
2020-3-16 18:56:00

So I guess I cannot use a virtual connection?


popa.bogdanp
2020-3-16 18:57:45

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


anything
2020-3-16 18:58:01

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


popa.bogdanp
2020-3-16 18:59:09

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.


popa.bogdanp
2020-3-16 18:59:11

My pleasure!


samth
2020-3-16 19:19:33

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.


anything
2020-3-16 19:22:33

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.


popa.bogdanp
2020-3-16 19:23:55

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


samth
2020-3-16 19:24:04

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


popa.bogdanp
2020-3-16 19:24:52

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.


anything
2020-3-16 19:25:19

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


popa.bogdanp
2020-3-16 19:25:58

Oh, sorry, I misread the query.


popa.bogdanp
2020-3-16 19:26:53

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


anything
2020-3-16 19:27:16

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


anything
2020-3-16 19:27:40

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


popa.bogdanp
2020-3-16 19:28:10

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


popa.bogdanp
2020-3-16 19:28:41

What OS are you on?


anything
2020-3-16 19:29:15

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.)


popa.bogdanp
2020-3-16 19:29:33

select sqlite_version() should return it


popa.bogdanp
2020-3-16 19:29:57

I made packages that distribute a recent version of SQLite3


anything
2020-3-16 19:30:02

Thanks! Mine is 3.13.0.


popa.bogdanp
2020-3-16 19:30:51

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


anything
2020-3-16 19:31:02

:smile:


anything
2020-3-16 19:31:30

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


popa.bogdanp
2020-3-16 19:32:37

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


anything
2020-3-16 19:33:36

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


popa.bogdanp
2020-3-16 19:36:19

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.


anything
2020-3-16 19:39:02

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. )


samth
2020-3-16 19:41:08

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


anything
2020-3-16 19:44:04

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?


popa.bogdanp
2020-3-16 19:45:07

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


anything
2020-3-16 19:45:40

I’m running it with a program called SQLiteStudio.


popa.bogdanp
2020-3-16 19:45:56

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


anything
2020-3-16 19:46:13

Hm, good point!


popa.bogdanp
2020-3-16 19:46:35

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


anything
2020-3-16 19:48:41

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


jestarray
2020-3-16 20:21:38

woahhh


jestarray
2020-3-16 20:21:45

since when did racket have pattern matching?


spdegabrielle
2020-3-16 20:22:10

Jurassic


marcelovmaciel
2020-3-16 21:23:30

@marcelovmaciel has joined the channel



anything
2020-3-17 00:35:29

@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!)


samth
2020-3-17 01:05:51

That’s just the migration to SVN


samth
2020-3-17 01:06:01

It’s much older than that



samth
2020-3-17 01:07:59

And really that commit is a CVS artifact


sorawee
2020-3-17 02:43:20

Ohhh