GithubHelp home page GithubHelp logo

Comments (7)

jkleinsc avatar jkleinsc commented on July 23, 2024

@gr2m the number in the middle is the "type" of ID used.

If the id is undefined the value is 0, if the id is a number, the value is 1, if the id is a string the value is 2, and if the id is an object the value is 3. For example:

Given an object of type author with the following ids:

var authorId = 123;
var relPouchId = db.rel.makeDocID({
  id: authorId,
  type: 'author'
});
//relPouchId = 'author_1_123'

var authorId = 'onetwothree';
var relPouchId = db.rel.makeDocID({
  id: authorId,
  type: 'author'
});
//relPouchId = 'author_2_onetwothree'

var authorId = { foo: 'bar' };
var relPouchId = db.rel.makeDocID({
  id: authorId,
  type: 'author'
});
//relPouchId = 'author_3'

The reason for these numbers is sorting/collation so that ids sort as follows:
// undefined < numbers < strings < object

The only use case I have seen for the undefined and "object" id is when you are looking for a range of docs using startkey/endkey and you use a start key with an id of undefined and an end key with an object id to get the "max value", eg as used here: https://github.com/nolanlawson/relational-pouch/blob/7f3b34f70be189cabbdf0f525b64f6be464b0921/lib/index.js#L425

from relational-pouch.

gr2m avatar gr2m commented on July 23, 2024

This is a great explanation, thanks John! Maybe we can add this to or link this from the README?

from relational-pouch.

jkleinsc avatar jkleinsc commented on July 23, 2024

@gr2m yeah, I think it could be added here: https://github.com/nolanlawson/relational-pouch#dbrelmakedocidparsedid
@nolanlawson Did I properly explain the reasoning for the middle part of relational-pouch ids above?

from relational-pouch.

nolanlawson avatar nolanlawson commented on July 23, 2024

@jkleinsc Yep! :)

from relational-pouch.

broerse avatar broerse commented on July 23, 2024

@gr2m If you like to write a PR for the readme I will commit it.

from relational-pouch.

gr2m avatar gr2m commented on July 23, 2024

@broerse #69

from relational-pouch.

broerse avatar broerse commented on July 23, 2024

Thanks!

from relational-pouch.

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.