knadh / dictpress

A stand-alone web server application for building and publishing full fledged dictionary websites and APIs for any language.
https://dict.press
GNU Affero General Public License v3.0
357 stars 41 forks source link

Need a strategy to generate guid for entries #12

Closed asdofindia closed 3 years ago

asdofindia commented 3 years ago

The sample.sql uses guid like MD5('apple-1'), etc. If we have a sorted list of words, we can predictably create guids like this.

But, when a random word is being inserted, how do we generate a guid?

One option is to make a fixed strategy for generating guid. Something like this:

# pseudocode
let newWord = 'apple'
let existingCount = count (*) from entries where word = 'apple'
let newCount = existingCount + 1
let guidKey = `newWord-${newCount}`
let guid = MD5(guidKey)

Another option is to drop the guid column if it is not important or if it can be generated from the other columns.

Related questions:

  1. Do you have a link to a script which you use for inserting data into alar?
  2. What's the purpose of guid?
knadh commented 3 years ago

The GUID just has to be a unique string, that's all. It can be a completely random UUID too. It's been provisioned for future scenarios like:

When distributing datasets, using numeric IDs as the unique identifiers for an entry isn't ideal. Can convey the wrong idea of a sequence, for example.

asdofindia commented 3 years ago

Okay. So a guid is an actual random guid/uuid. Makes sense.