Why are keys strings?

11 views
Skip to first unread message

Aaron Cohen

unread,
Apr 12, 2010, 2:35:57 PM4/12/10
to FleetDB
FleetDB is pretty fun to use, I've been experimenting with it on a
class project lately, so thanks!

I like to do stuff like:

(db "insert" "collection" {:id 1 :name "Aaron"})

However, to read this, I have to do:

(get (db "select" "collection" {"where" ["=" :id 1]}) "name")

And the use of a string parameter to "get" is troubling to me. I'd
much prefer to say:

(:name (db "select" "collection" {"where" ["=" :id 1]}))

Is this related to the use of json as query transport?

Mark McGranaghan

unread,
Apr 12, 2010, 2:53:26 PM4/12/10
to fle...@googlegroups.com
On Mon, Apr 12, 2010 at 2:35 PM, Aaron Cohen <reml...@gmail.com> wrote:
> FleetDB is pretty fun to use, I've been experimenting with it on a
> class project lately, so thanks!

Good to hear!

> I like to do stuff like:
>
> (db "insert" "collection" {:id 1 :name "Aaron"})
>
> However, to read this, I have to do:
>
> (get (db "select" "collection" {"where" ["=" :id 1]}) "name")
>
> And the use of a string parameter to "get" is troubling to me. I'd
> much prefer to say:
>
> (:name (db "select" "collection" {"where" ["=" :id 1]}))
>
> Is this related to the use of json as query transport?

Right; JSON does not support keyword types. More generally, I designed
FleetDB to be accessible from a variety of languages, including ones
like Java and Python that don't have native support for keywords. For
these languages to interact nicely with FleetDB I had to avoid baking
in the concept of keywords.

- Mark

>
> --
> To unsubscribe, reply using "remove me" as the subject.
>

Aaron Cohen

unread,
Apr 16, 2010, 12:29:33 AM4/16/10
to fle...@googlegroups.com
Just a note for people who might be like me and not have realized it,
but you can destructure string keys too, I had thought it only worked
with symbols. You have to use :strs instead of :keys, but it works
great.

For instance if your query returns {"id" 1, "fname" "Aaron", "lname" "Cohen"}

(let [{:strs [id fname lname]} {"id" 1, "fname" "Aaron", "lname"
"Cohen"}] [id fname lname]) -> [1 "Aaron" "Cohen"]


--
Subscription settings: http://groups.google.com/group/fleetdb/subscribe?hl=en
Reply all
Reply to author
Forward
0 new messages