Fork me on GitHub
#beginners
<
2021-09-28
>
quan xing02:09:20

How can I pagination mysql's data in Clojure

lsenjov04:09:02

When fetching? By using sql LIMIT and OFFSET

lsenjov04:09:50

Or by using an sql CURSOR

lsenjov04:09:05

If these don’t meet your needs, we could use more details on your use case @imxingquan

quan xing07:09:49

yes by By using sql `LIMIT` and `OFFSET` . Should I need to write 2 sql 'select count' and 'select limit', shouldn't I?

👍 1
lsenjov08:09:56

Or check the number of results you're getting back. Depends what you're doing with it

dharrigan08:09:00

Tis a bad idea, generally to use LIMIT and OFFSET for doing pagination, it becomes a bigger bigger problem for larger and larger result sets

quan xing08:09:15

Is there a good way to solve this problem

Ed08:09:45

https://stackoverflow.com/questions/802373/how-to-count-and-limit-record-in-a-single-query-in-mysql ... Mysql will let you get the total number of rows without running the whole query twice.

quan xing09:09:43

wow, thank you @l0st3d.

papachan12:09:26

Hi. is there a method to replace dash by underscore with keywords?

papachan12:09:38

excluding the string/replace

papachan12:09:54

found it : (csk/->snake_case :s3-key :separator \-)

walterl14:09:21

Interesting. Which lib is that, providing ->snake_case?

Benjamin15:09:18

(def foosym ^{:foo 10} (fn []))
does this not put the meta on the function? Where do I find the meta data when I do it like this?

delaguardo15:09:00

it puts metadata to the function not the var

(def foosym ^{:foo 10} (fn []))

(meta @#'foosym) ;; => {:foo 10}

Alex Miller (Clojure team)15:09:27

functions (generically) do not support metadata (although some impls do in some cases)

Alex Miller (Clojure team)15:09:25

that is, in impl types, IFn does not extend IMeta

delaguardo15:09:08

but then why this happen?

(def foosym ^{:foo 10} (fn []))

(meta @#'foosym) ;; => {:foo 10}

didibus18:09:49

But the interface IFn and Fn don't have too. Functions created with (fn ...) are going to be AFunction so that they can have meta which tells you the function name and column/line and all that I believe.

didibus18:09:27

But all other functions not created with fn unless they themselves implements IObj and IMeta won't support metadata.

Alex Miller (Clojure team)15:09:41

> (although some impls do in some cases)

Alex Miller (Clojure team)15:09:30

but I would not generally rely on this

Alex Miller (Clojure team)15:09:57

if you read https://clojure.org/reference/metadata, it says "Note that metadata reader macros are applied at read-time, not at evaluation-time, and can only be used with values that support metadata, like symbols, vars, collections, sequences, namespaces, refs, atoms, agents, etc."

Benjamin15:09:22

(defn ^{} foo []) 
is good right? now you I get the mets from the var

Alex Miller (Clojure team)15:09:42

that is the more normal place to put metadata, yes

👍 1
walterl15:09:43

Speaking of interfaces like IFn and IMeta: I often see pertinent mentions of Clojure implementation details (most often interfaces), in in-depth answers to some more advanced questions. Is there a recommended resource (book/site/other) for learning about the most important bits of Clojure's implementation, and how they fit together?

Alex Miller (Clojure team)15:09:56

I do not think that exists anywhere. There are some info and diagrams in Clojure Applied that cover parts of it

Alex Miller (Clojure team)15:09:25

specifically the collection/seq parts

walterl15:09:46

Thanks, @alexmiller. That's the kind of answer I was expecting. 👍

Jim Strieter17:09:17

Is there any way to use Intelli-J/Cursive to generate clojure bindings for a local java projct?

Sam Ferrell18:09:21

How do I discriminate between values like '[:foo 1] and [:foo 1] ?

hiredman18:09:00

after evaluation they are the same

hiredman18:09:06

user=> ''[:foo 1]
(quote [:foo 1])
user=>
before evaluation ' is a reader macro that wraps things in a list where the first item in the list is the symbol quote

hiredman18:09:45

usually if you are trying to distinguish the two you are starting to make a mistake with macros

Sam Ferrell18:09:41

Trying to write a function that accepts either a Datomic/Datascript query '[:find ...] or a pull expression against a default query

hiredman18:09:39

for a function, functions receive evaluated arguments, in which case '[:foo 1]and [:foo 1] are identical

Sam Ferrell18:09:01

Gotcha, that makes sense