This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-08-22
Channels
- # announcements (13)
- # babashka (22)
- # beginners (22)
- # biff (17)
- # calva (6)
- # clerk (20)
- # clj-kondo (25)
- # clj-together (5)
- # clj-yaml (20)
- # cljdoc (16)
- # cljs-dev (1)
- # clojure (42)
- # clojure-brasil (1)
- # clojure-europe (26)
- # clojure-nl (6)
- # clojure-norway (24)
- # clojure-turkiye (3)
- # clojure-uk (5)
- # clojurescript (37)
- # core-async (7)
- # core-logic (2)
- # datalevin (7)
- # datomic (43)
- # events (2)
- # fulcro (7)
- # gratitude (1)
- # hyperfiddle (7)
- # java (7)
- # jobs (3)
- # lsp (4)
- # off-topic (16)
- # pathom (18)
- # polylith (1)
- # portal (27)
- # reitit (4)
- # releases (3)
- # shadow-cljs (47)
- # tools-build (14)
- # tools-deps (16)
- # yamlscript (11)
For the https://github.com/damn/Cyber-Dungeon-Quest I am developing, I am creating an editor at the moment for the domain objects. There are 120 creatures and also same number of items which have modifiers, creatures have skills and items, skills have effects, etc.
At the moment I am keeping all the values in different .edn
files. But I have the feeling it becomes complicated to read and save the edn files all the time to edit the values (If I want to change one attribute of one creature I have to load and save the whole file with all 120 creatures every time), so I am thinking of using a database for this. I was considering using datomic for it, but not sure it is the right way?
I am saving all effect/weapon damage as a single floating point number which gets multiplied by the default-damage
at the start of the game.
How do I create the schema id for such properties? This is how it looks at the moment:
{:id :weapon/defaults, :range 0.5, :action-time 500, :damage [5 10]}
Properties should be unique, so maybe something like :property/name
?Or should I use enums for this, an enum for each property ? Other properties are for example game-speed, window resolution, etc.
120 (or even thousands) doesn’t sound like very much… you could keep it in a single .edn file
Setting up datomic (or any db) might be useful in the long term but if you are still prototyping and figuring things out, it might not be worth it in the beginning.
there’s also datalevin (which doesn’t have temporal capabilities) but uses LMDB which might be better suited for embedding in a game
also a datalog query language allows you to ask questions about the data in a more convenient way
But just for curiosity, how would I define these one-off properties ? As enums or with a unique id key ?
Hi, I am trying to create a recursive rule. For the following data:
{:db/id 17592186045422,
:a.b/name "a.b",
:permission/owner-id [#:db{:id 17592186045421}],
:parent/_id
[{:db/id 17592186045423,
:a.b.c/name "c1",
:permission/owner-id [#:db{:id 17592186045419}],
:parent/_id [{:db/id 17592186045425, :a.b.c.ol/name "ol1"}
{:db/id 17592186045426, :a.b.c.ol/name "ol2"}]}
{:db/id 17592186045424,
:a.b.c/name "c2",
:permission/owner-id [#:db{:id 17592186045420}],
:parent/_id [{:db/id 17592186045427, :a.b.c.ol/name "ol3"}]}]}
How can I make a recursive rule to check the owners, moving up the tree from the lowest level?
(def rec-rule '[[(rowns ?e ?user-id)
(?c :permission/owner-id ?u)
(?u :user/id ?uid)
]
[(rowns ?e ?user-id)
(?e :parent/id ?p)
(rowns ?p ?user-id)
]])
then
(d/q '[:find ?e ?uid
:in $ % ?name ?uid
:where
(rowns ?e ?uid)
[?e :a.b.c.ol/name ?name]]
db
rec-rule
"ol2"
2)
Thank you in advanceYou need to bind the same variables in the head inside the body and be consistent about the attributes in your data (like in your data you use :parent/_id). something like: (def rec-rule '[[(rowns ?e ?user-id) [?e :permission/owner-id ?u] [?u :user/id ?user-id]] [(rowns ?e ?user-id) [?e :parent/_id ?p] (rowns ?p ?user-id)]])
it works:
(def rec-rule '[[(rowns ?e ?user-id)
[?e :permission/owner-id ?u]
[?u :user/id ?user-id]]
[(rowns ?e ?user-id)
[?e :parent/id ?p]
(rowns ?p ?user-id)]])
Cross-posting here: https://clojurians.slack.com/archives/C06MAR553/p1692742016940649
i skimmed through everything, maybe i missed it, what is your guidance for seeing the present state the schema , like today i have directory filled with EDN files, roughly each entity type gets its own EDN file, and if i want to add a new attribute i append to that file. In this setup would you recommend i look at the base EDN then each schema migration searching for any additional attributes on the entity type ? or ?
For retrofitting into an existing project, caribou can simply take over new migrations using epoch zero. I don’t think there is a good way to get caribou to “incorporate” your existing schema other than tedious translation of entity zero to corresponding transaction(s). Then, you will be faced with a second challenge: can you re-transact your schema using caribou without consequence? I don’t think it can be done. Shooting from the hip, there is still hope in this kind of approach: Build up your existing schema into caribou-compatible migrations as epoch zero. Then create new migrations in epoch one. For testing, have caribou migrate epoch zero then epoch one. For “production”, only migrate epoch one. The epoch numbers are arbitrary so you could make the existing state be epoch -1 and the new stuff epoch zero (the default) as a kind of safety mechanism.
Actually, if you are adventurous, you could “fake” a caribou migration that includes your existing (forensically constructed) schema. Then you could keep everything in epoch zero and have the best experience for testing and documentation and such. I didn’t foresee this requirement but it would not be hard to generate a fake migration.
hm i’ll have to play around , to see, our current schema can’t be transacted in 1 transaction either
That’s not a problem for this approach: you could fake N migrations. The key is to get them into a source file that can then be hashed correctly.
Not necessarily. I use aero to split it up into separate EDN files. And, on top of that, you can generate the tx-data
with tx-data-fn
to get the data out of any EDN or non-EDN file if you want.
Caribou doesn’t care about where you source the data. You could put the whole thing in a .clj
file, but I think that defeats the documentation and migrations-as-values concept.
A mix (using tx-data-fn
and/or aero) is a good compromise. The key is that wherever it comes from, it must yield immutable tx-data.
I’ll make a note to update the README since, in hindsight, bootstrapping into an existing dn is likely to be a common request.
I just pushed a commit that adds support for “adopting” an existing database via the claim!
function. The README has been guidance on how to adopt an existing database.
Seems to be some overlap with conformity? https://github.com/avescodes/conformity what would you say is the most important difference?
Doesn’t require a transaction fn (only the built-in cas
). Works with Cloud. Considers migrations as a dependency graph (allowing for concurrent development) versus a linear sequence. But there is no doubt the two are in the same space.
I wish this was here 3 years ago. 🙂 Thanks for the release!
LOL … I very nearly released it two and a half years ago, but my OSS career got sidetracked by employment where Datomic was not in the picture.
in Hungary swallows, storks, wild goose and crows are the most well-known migratory animals, so i might have named named a library accordingly 🙂
> allowing for concurrent development what does that mean more specifically? different code branches can have different graphs?
Yes, branches is a good example. Branch A only needs migration A and its dependencies X, Y & Z. Branch B only needs migration B and its dependencies X, Y & Z. Either branch’s migrations could be applied to a shared dev database first. Either branch’s migrations could appear first in the EDN file defining all migrations (facilitating merges) and either branch could be deployed before the other, regardless of the order in which it appears in the EDN file. Another more extreme example is a set of apps that share a production database. A shared EDN file could describe common migrations and individual EDN files could hold the app-specific migrations.