Coder Social home page Coder Social logo

Auto Generated Unique Key about level HOT 11 CLOSED

rupamking1 avatar rupamking1 commented on September 26, 2024
Auto Generated Unique Key

from level.

Comments (11)

rupamking1 avatar rupamking1 commented on September 26, 2024 1

@vweevers Extremely sorry for my word, you are so helpful, Thank You for Helping me.

from level.

vweevers avatar vweevers commented on September 26, 2024

Multiple solutions exist for this. Depends on several factors: how do you want your keys to be sorted, should they be globally unique, are your writes random or sequential, do you delete keys and if so do you want to allow reuse, etc. This is all up to you.

Can you be more specific?

from level.

rupamking1 avatar rupamking1 commented on September 26, 2024

@vweevers I want globally unique & sequential, it may delete and reuse.
Can you please send an example?

from level.

vweevers avatar vweevers commented on September 26, 2024

Using ulid as keys may work for you. E.g.:

const ulid = require('ulid').monotonicFactory()

await db.put(ulid(), 'example')

from level.

rupamking1 avatar rupamking1 commented on September 26, 2024

ulid() will this package never genarate same id, every time will it genarate unique id?

Can i use uniqid/nanoid/uuid package for Maintaining Global Uniqueness?

from level.

vweevers avatar vweevers commented on September 26, 2024

ulid() will this package never genarate same id, every time will it genarate unique id?

It has 80 bits of randomness (see spec). Should be sufficiently unique, but that's your call.

Can i use uniqid/nanoid/uuid package for Maintaining Global Uniqueness?

The benefit of ulid is that the generated ids sort lexicographically and increase monotonically. If you stream or iterate keys from your db, you get them back in insertion order.

from level.

rupamking1 avatar rupamking1 commented on September 26, 2024
  1. Yes, I understood but this repository not upgrade till 2019, Can you please a recently upgraded repository?

  2. leveldb performance is High in sequential key or in random key, which one make leveldb performance better?

from level.

vweevers avatar vweevers commented on September 26, 2024

Sequential, for sure.

from level.

rupamking1 avatar rupamking1 commented on September 26, 2024

@vweevers Please answer my questions

  1. Yes, I understood but this repository not upgrade till 2019, Can you please a recently upgraded repository?
  2. leveldb performance is High in sequential key or in random key, which one make leveldb performance better?

from level.

vweevers avatar vweevers commented on September 26, 2024

Your tone is too demanding - also in ulid/javascript#88 - and I frankly don't feel like explaining why that is an issue. So I'm just gonna leave this thread until you realize it yourself. Good luck!

from level.

vweevers avatar vweevers commented on September 26, 2024

Thank you! To answer your first question:

Yes, I understood but this repository not upgrade till 2019, Can you please a recently upgraded repository?

ulid is stable as far as I know, and dependency-free, so naturally it's light on maintenance. I don't know of other UUID generators that sort in the same way, but I'm sure they can be found.

For inspiration, you might want to look at flakeid (written in Go but conceptually relevant), monotonic-lexicographic-timestamp (only unique per-machine, not globally) and modules listed in awesome.

Lastly, you can of course write your own solution, which has the benefit that you can optimize it for your specific use case. For example, let's say you have a cluster of machines and you already have a known distinct name for each machine, then you could construct keys in the form of <timestamp>~<name> or <sequence number>~<name>.

from level.

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.