-
-
Save abhi18av/fb1abf5f9a70b5941e1894da02d4516e to your computer and use it in GitHub Desktop.
GroovyScript + Datomic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Dont know why but it requires java 17 fx | |
// sdk install 17.0.8.fx-zulu | |
// sdk use java 17.0.8.fx-zulu | |
@Grapes([ | |
@Grab(group='org.scalamolecule', module='datomic-client-api-java-scala_2.13', version='1.0.3'), | |
@Grab(group='com.datomic', module='local', version='1.0.267'), | |
@Grab(group='com.cognitect', module='http-client', version='1.0.126'), | |
]) | |
import datomicJava.client.api.sync.* | |
import static datomic.Util.*; | |
client = Datomic.clientDevLocal("mem") | |
client.deleteDatabase("hello") | |
client.createDatabase("hello") | |
db = client.connect("hello") | |
db.transact(list( | |
map( | |
read(":db/ident"), read(":movie/title"), | |
read(":db/valueType"), read(":db.type/string"), | |
read(":db/cardinality"), read(":db.cardinality/one"), | |
read(":db/doc"), "The title of the movie", | |
), | |
map( | |
read(":db/ident"), read(":movie/genre"), | |
read(":db/valueType"), read(":db.type/string"), | |
read(":db/cardinality"), read(":db.cardinality/one"), | |
read(":db/doc"), "The genre of the movie" | |
), | |
map( | |
read(":db/ident"), read(":movie/release-year"), | |
read(":db/valueType"), read(":db.type/long"), | |
read(":db/cardinality"), read(":db.cardinality/one"), | |
read(":db/doc"), "The year the movie was released in theaters", | |
) | |
)) | |
db.transact(list( | |
map( | |
read(":movie/title"), "The Goonies", | |
read(":movie/genre"), "action/adventure", | |
read(":movie/release-year"), 1985 | |
), | |
map( | |
read(":movie/title"), "Commando", | |
read(":movie/genre"), "thriller/action", | |
read(":movie/release-year"), 1985 | |
), | |
map( | |
read(":movie/title"), "Repo Man", | |
read(":movie/genre"), "punk dystopia", | |
read(":movie/release-year"), 1984 | |
) | |
)) | |
result = Datomic.q('''[ | |
:find ?movie-title :in $ ?year | |
:where [?e :movie/release-year ?year] [?e :movie/title ?movie-title] | |
]''', | |
db.db(), | |
1984L | |
) | |
result.each{ | |
println "Result $it" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment