Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I assume you used these against a relational database? Did you commit those ids with the prefix still attached? or did you `.split()[1]` or something?

I think it's a pretty good idea. I'm just wondering how this translated to other systems.



We were using Mongo and stored the ids with the prefix in the DB as the primary key. Pretty much everywhere we were passing them around as strings, never as 128 bit int, so there was no integrity checking outside of the app layer.

The only drawback was marshalling the types when they come out of the db layer. Since the db library types were string we had to hard cast them to the correct types, really my only pain. That isn't such a big deal, but it means some object creation and memory waste, like:

    // pseudo code:
    const results = dbclient.getObjectsByFilter( ... );
    return results.map(result => ({
        id: result.id as ObjectId,
        ...
    }));
We normally didn't do it, but it would be at that time you could have some `function isObjectId(id:string) : id is ObjectId { id.beginsWith("object:"); }` wrapper for formal verification (and maybe throw exceptions on bad keys). And we were probably doing some type conversions anyway (e.g. `new Date(result.createdAt)`).

If we were reading stuff from the client or network, we would often do the verification step with proper error handling.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: