Fork me on GitHub
#datalevin
<
2022-02-22
>
Norman Kabir00:02:10

I'm scripting the creation of Datalevin database for testing. Is this the preferred method to create a new database with schema using dtlv?

$ dtlv exec << EOF
(def conn (get-conn "/tmp/test-db"))
(close conn)
EOF
With an associated update-schema call? https://github.com/juji-io/datalevin/blob/master/doc/dtlv.md#shell-command

Huahai22:02:21

this should work

Norman Kabir16:02:01

The (help) for dtlv indicates:

Datalevin (version: 0.5.28)

  Type (help) to see available functions. Clojure core functions are also available.
  Type (exit) to exit.
  
user> (help)

In addition to Clojure core functions, the following functions are available:

In namespace datalevin.core
So clojure.core functions should be available. But
user> (load-file "demo.edn")
Could not resolve symbol: clojure.core/load-file

Huahai22:02:50

What is load-file, I don’t think datalevin has such a function

Huahai23:02:13

oh you mean clojure.core function

Huahai23:02:48

sorry, i should rephrase it, it’s not clojure.core, but rather the part of clojure.core functions that are implemented by sci

borkdude23:02:48

load-file doesn't come with SCI by default but it's fairly easy to implement

Huahai23:02:17

thx for letting us know. If people really need some functions, we can probably implement them, either in sci or datalevin.

borkdude23:02:56

sci only has "safe" functions by default, no functions that access the file system

borkdude23:02:21

babashka implements load-file just by slurping the file and then calling sci/eval-string on that, while binding sci/file to the filename

Huahai23:02:04

It makes sense.

Huahai23:02:19

@URMJAL866 I would like to see a use case where load-file is necessary for using Datalevin

Norman Kabir23:02:40

Hi @U0A74MRCJ I wanted to use dtlv to set up a database via a bash script:

dtlv exec << EOF 
(def c (get-conn "${DATABASE_DA:?}"))
(def schema ${schema:?})
(update-schema c schema)
(close c)
EOF
I wanted to load the schema from an edn file. As a workaround, I created a bash variable and assign it as above. Direct loading would be much nicer.

Norman Kabir11:02:28

https://clojurians.slack.com/archives/C01RD3AF336/p1645571301374099?thread_ts=1645546081.277929&amp;cid=C01RD3AF336 @U04V15CAJ I read about this in the babashka docs but it's not clear to me which features are exposed within the dtlv interpreter:

Datalevin (version: 0.5.28)

  Type (help) to see available functions. Clojure core functions are also available.
  Type (exit) to exit.
  
user> (require 'sci/file)
Could not find namespace sci/file.
user> file
Could not resolve symbol: file

borkdude11:02:26

These things are not exposed in the interpreted scripts, but exposed in the interpreter API for creating script environments.

Norman Kabir02:02:27

So it is something that needs to be exposed via Datalevin rather than a script I would write independently?

Huahai23:02:14

0.5.29 was released yesterday. it includes a fix by @denik thanks!

👍 1
Huahai23:02:29

plan to release a new version soon for a few other fixes.

Huahai23:02:19

Please file issues in addition to discussing here, as I normally work through the issues when I get some time to work on Datalevin. Thanks!

Norman Kabir23:02:15

Congratulations! And, thank you!