Fork me on GitHub
#xtdb
<
2023-08-15
>
ianjones04:08:45

I want to string search on a field called name but i want to ensure im lower casing the values im searching on.. how do I accomplish this?

ianjones04:08:54

(q db '{:find [name (pull workout [*])]
                                          :in    [[search user]]
                                          :where [[workout :workout/name name]
                                                  [(clojure.string/includes? name search)]]
                                          :order-by [[name]]}
                                     [(string/lower-case (or (:search params) "")) (:uid session)])

ianjones04:08:59

this is what im working with

ianjones04:08:39

i see the string functions but adding (lower name) throws an error

tatut04:08:38

Lucene index is best for FTS, calling the includes function needs to consider every doc that has the name attr.

tatut04:08:21

You can call clojure fn to do the lowering in query as well [(clojure.string/lower-case name) lower-name] and use that

2
ianjones04:08:18

right that makes sense, time to learn about indexing 😄

tatut06:08:51

you can use < and > etc on strings as well, but that obviously works from the start of the string only

2
tatut06:08:03

and is case sensitive

2
zeitstein12:08:19

Can a transaction function access the operations submitted before it (during the same transaction)?

jarohen12:08:37

yes, it'll see the effect of prior operations within the transaction

zeitstein12:08:40

Right, but can I actually get e.g. the list of put ops and documents that come before it?

jarohen12:08:05

ah, I see - not as operations, no, not a use case we'd considered :thinking_face:

zeitstein12:08:03

I'm imagining a final tx fn that would determine what else might need to be done, based on what was transacted before it.

zeitstein12:08:31

I could do this before submitting the tx, but then I might need to think about staleness.

jarohen12:08:49

right, yep

jarohen12:08:08

would it also be an option to widen the scope of your tx-fn?

jarohen12:08:25

you could potentially also put a separate event-like document earlier in your tx that you then query for in the tx-fn?

zeitstein12:08:09

Hm, I'll consider that. > would it also be an option to widen the scope of your tx-fn? How do you mean? (If the msg below wasn't a continuation of that thought :))

jarohen12:08:45

as in, make the tx-fn your whole transaction - the prior operations, and the part that needs to react to them?

zeitstein12:08:10

Aaah, yes, that could work 🙂

jarohen12:08:28

although maybe that wouldn't work if you needed to query the results of the earlier operations - you only get chance to mutate the DB with the return value of the tx-fn

jarohen12:08:04

but you could perhaps query enough to see what those operations would do (i.e. it'd be like doing it at submit but without the staleness issue)

zeitstein12:08:08

> although maybe that wouldn't work if you needed to query the results of the earlier operations That is a good point. Would be more convenient to be able to do that, but should be workaround-able 🙂 Thanks for the quick reply, James. Cheers!

jarohen12:08:23

np, good luck 🙏

Nikolas Pafitis14:08:01

Is it possible to rollback of the database to before a transaction if i know the transaction id?

zeitstein14:08:52

I don't think so? You should have enough information to generate a new transaction such that the data in the db after it will be as if it was rolled back. In other words, you would 'revert' all intermediate transactions.

2
refset15:08:47

Hey @U05F70RT9RQ I'm curious, is this just a dev / testing thing? Or do you have some production use case for that?

Nikolas Pafitis15:08:59

It's about migrating, and then rolling back if something goes wrong. What would be the best practice?

refset16:08:40

How do you define/measure "if something goes wrong"? XT's transactions are ideally usable for this, although I appreciate the atomicity may not be appropriate, especially if you have a LOT of data and need to avoid stalling concurrent transactions. How much data are you likely migrating? Roughly what size are the smallest boundaries of atomicity you could use? Is there a concurrent workload (i.e. it's a 'live' migration)? In the worst case I think you should be able to build up some userspace 'transaction' metadata that re-creates the kind of atomicity you are looking for.

refset15:08:06

Hey folks 👋 I'm going to run an 'office hours' style Virtual Meetup session today, starting in 20m if anyone's about to chat and wants to ask questions / listen to others! There's no fixed agenda or presentation, with exception of attempting to tackle @hairfire’s recent question about adapting one of the Learn XTDB Datalog Today examples into a 2.x query 🙂 you can sign up here: https://www.eventbrite.com/e/xtdb-virtual-meetup-tickets-526824956627

refset15:08:02

...or you can join direct if that's preferable: https://meet.google.com/bcu-sqkw-ckf

refset16:08:31

great to meet & chat just now @U0CKDV6DB, @UGNMGFJG3 - whilst I'm no expert on statecharts or ClojureDart (currently!) I hope the tips on Lucene and transaction functions tests will be of use. Always feel free to ping me if you ever want more tips :)

🙌 2
ianjones16:08:00

thanks! it was nice to meet you both. ClojureDart does look intriguing and I love the history lesson on datalog

☺️ 2
hairfire16:08:02

Sorry, I was unavailable for this meeting time

👌 2
hadils16:08:11

Just FYI @U899JBRPF. I implemented a simple state machine in 2 lines! Thanks for getting me out of my head there.

🔥 4
curtosis16:08:13

@U899JBRPF did this happen to get saved anywhere? I was away and didn’t get to join.

refset19:08:40

unfortunately not this time - sorry @U050N4M9Z - but I will run another session on Wednesday and try to give everyone some more notice...and get into the habit of recording again 🙂

👍 2
curtosis19:08:25

no worries! I’ll just have to wrestle with it myself the old-fashioned way. 🙂

refset20:08:24

well I would be happy to chat in the meantime or start a new thread here - no need to punish yourself(!

😄 2