Giter Club home page Giter Club logo

Comments (6)

zh217 avatar zh217 commented on May 18, 2024 1

You can have a ?[] together with a :create in the same query. In addition, there are some utilities in the python client that allows you to do simple mutations:

db.put('rel_name', {'a': 1, 'b': 2})
db.put('rel_name', [{'a': 1, 'b': 2}, {'a':3, 'b': 4}])

The 'why' is that queries are not only hand-written, but also generated by machines (in fact in our own use, more queries are auto-generated). So reducing ambiguity is a priority. Reducing boilerplate is a job for language-specific clients.

from cozo.

gisborne avatar gisborne commented on May 18, 2024

This is also confusing:

:create test {name: String}

?[a] <- [['Cozo']]

:put test {a}

query::relation_not_found

× Cannot find requested stored relation 'test'

from cozo.

atlewee avatar atlewee commented on May 18, 2024

It seems like you cant create and put in the same query/transaction.
If you first run the create and then the put as separate queries it will work.

Or you can run multiple queries at once by wrapping them in curlybrackets.
This works:

{
:create test {name: String}
}
{
?[name] <- [['Cozo']]
:put test {name}
}

If you want to keep the a as binding name:

:create test {name: String}

?[a] <- [['Cozo']]
:put test {name=a}

from cozo.

gisborne avatar gisborne commented on May 18, 2024

Thanks for that.

I am still confused about a couple of things.

This works:

{
:create _test {name: String}
}
{
?[name] <- [['Cozo']]
:put _test {name}
}

So an ephemeral relation is within a single script, not a single transaction? I guess.

But why does this not work?

{
:create _test {name: String}
}
{
:put _test {['Cozo']'}
}

I tried 'Cozo', ['Cozo'] and [['Cozo']] and none of those worked.

from cozo.

zh217 avatar zh217 commented on May 18, 2024

You can't, these variables in :put doesn't refer to a single value. It is working as expected.

If you are :createing, you can omit :put while also have ?[a] available and it will insert the value as documented here.

from cozo.

infogulch avatar infogulch commented on May 18, 2024

I don't understand the purpose of this restriction, it feels arbitrary. Why is binding to a variable required when there is only one possible value?

{
:create _test {name: String, kind: String}
}
{
:put _test {name: 'Cozo', kind: 'DB'}
}
# why can't this↑ be desugared to this↓ automatically?
{
?[name, kind] := name = 'Cozo', kind = 'DB'
:put _test {name, kind}
}

It works for querying, why not :put?


{
:create _test {name: String, kind: String}
}
{
?[name, kind] := name = 'Cozo', kind = 'DB'
:put _test {name, kind}
}
{
?[kind] := *_test{name: 'Cozo', kind}
}

from cozo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.