incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Benoit Chesneau <bchesn...@gmail.com>
Subject Re: Rewrite /user/bob to user:bob
Date Fri, 19 Aug 2011 08:20:47 GMT
On Thu, Aug 18, 2011 at 8:47 PM, Simon Leblanc <sim.leblanc@gmail.com> wrote:
> Hello,
>
> I'm trying to write a couchapp with multiple users. Two users can't have the same name,
since I want to access user bob's profile through /user/bob.
> Similarly, I store other documents (let's call them stuffs) with unique ids that I would
like to access through /stuff/somestuff.
> A user can have the same name as a stuff, and vice versa. That's why I can't use bob
or somestuff as _id (otherwise I couldn't have a stuff named bob or a user named somestuff).
>
> I see 3 options:
> use different databases for users and stuffs, but that means two design documents and
it kind of defeats the purpose of couchapps
> use uuids and deal with names in a custom manner. Sounds difficult. I would really prefer
the third option:
> use a naming convention for ids, like user:bob and stuff:somestuff.
>
> My favorite choice so far is the third option. The colon can be replaced by any character,
like dash, underscore, comma, @ or even nothing if this can help. The prefix can also be a
postfix.
> I initially tried with a forward slash which was perfect until I realized it was not
really supported and it caused problems with update functions (see COUCHDB-1229).
>
> Is it possible to rewrite /user/bob to, for instance, /_show/profile/user:bob or /_show/profile/user_bob
?
> I tried {"from": "user/*", "to": "_show/profile/user:bob"} and variants with no success.
>
> If it is not possible, what would be the best alternative?
>
> Thanks a lot for your help,
>
> Simon
>
>
> PS: For the sake of learning, I'm trying to write a pure couchapp without client-side
javascript…

Actually the best way to do it would be eventually passing the user as
a query parameter. /profile?user=bob

then :

{"from": "/profile", "to": "/_show/profile/:user" } where id is bob.
Easier way is coming, but not sure it will be in 1.2 .

- benoit

Mime
View raw message