datascript

Vincent 2024-10-21T23:57:35.106209Z

Ahoy maties! Is it possible to explain like I'm Newb how i can write to datascript with cross-erefrences to other keywords? I'm wanting to save appointment data and that looks like client service-provider staff-member and the three coming together on a Date is an appt. Something like that. When I want to add-appointment to my datascript db, I want to write references to the service-provider/id and to the staff-member/id etc But I'm having trouble.

Vincent 2024-10-22T12:30:59.917909Z

Thanks for your help so much, finally got it working. Am using something along the lines of [:client/id (uuid client-string)] because of how am storing uuids

✅ 1
Sam Ferrell 2024-10-22T02:14:08.225289Z

Sounds like each appointment is an entity and has at least 4 attributes, one for the date and the others are references to other entities (a client, a service provider, and a staff member). Does that sound about right?

Vincent 2024-10-22T02:35:08.503929Z

Yes, exactly. And then referenccing the other entities, I'm running into trouble getting them to transact, or getting them to show up. I am fairly confident the schema supports what I'm writing, but I'm not clear on if I should have the full UUID or the [:user/id #uuid] pattern

Sam Ferrell 2024-10-22T02:40:17.500569Z

This is one way to write a transaction that creates a new appointment with the relevant references. If the client/provider/staff entities have unique attributes you can use those in place of providing the database ID

(defn create-appointment [date client-id provider-id staff-id]
  [[:db/add -1 :appointment/date date]
   [:db/add -1 :appointment/client client-id]
   [:db/add -1 :appointment/provider provider-id]
   [:db/add -1 :appointment/staff staff-id]])

Sam Ferrell 2024-10-22T02:41:05.810859Z

And this would be the relevant schema

(def schema
  {:appointment/client   {:db/valueType :db.type/ref}
   :appointment/provider {:db/valueType :db.type/ref}
   :appointment/staff    {:db/valueType :db.type/ref}})

Sam Ferrell 2024-10-22T02:41:50.459059Z

Are you getting an error on transaction or just not seeing what you expect when you make a query?

Vincent 2024-10-22T03:11:59.208099Z

Right now I see 'Tempids used only as value in transaction: ("15589d57-a5eb-4d64-8e98-783c82a8cd2e")' even though the schema supports them with the :db.type/ref

Sam Ferrell 2024-10-22T03:16:26.822429Z

What does your transaction look like? If you want to use a UUID you'll need to make sure its a unique attribute and to use a look up ref like [:db/add -1 :appointment/client [:client/uuid "15589d57-a5eb-4d64-8e98-783c82a8cd2e"]]