Mendy
Mendy
Explore posts from servers
DTDrizzle Team
Created by Mendy on 10/31/2023 in #help
Smart or Idiotic? The Great BigInt-to-Hash Adventure!
I haven't forgotten, got caught up with urgent matters, will get to doing that soon.
58 replies
DTDrizzle Team
Created by Mendy on 10/31/2023 in #help
Smart or Idiotic? The Great BigInt-to-Hash Adventure!
If you are following through with this, I also made some changes to the type to help mitigate some issues, I’ll update the gist when I’m back.
58 replies
DTDrizzle Team
Created by Mendy on 10/31/2023 in #help
Smart or Idiotic? The Great BigInt-to-Hash Adventure!
I sent the message before leaving my house, when back, I’ll setup a box with the issues I’ve seen. If you have a small schema I can use and you can link it here it will be helpful.
58 replies
DTDrizzle Team
Created by Mendy on 10/31/2023 in #help
Smart or Idiotic? The Great BigInt-to-Hash Adventure!
@Angelelz just a heads up in case you’re considering using my type - I’ll advise against it. It appears that drizzle have LOTS of issues with custom types. The toDriver and fromDriver are not reliable, and will not fire on many occasions (prepared statements, nested query builder relationships and more…) In order to get binary ULID working this will have to be resolved. There are many issues open on GitHub related to this. For myself, I gave up on it for now, and will store my ids as in a varchar type.
58 replies
DTDrizzle Team
Created by Mendy on 10/31/2023 in #help
Smart or Idiotic? The Great BigInt-to-Hash Adventure!
I agree. I posted it here and gave the gist a good title so people have better chance of finding it when looking ulid and drizzle, posting it in the docs will be helpful for someone for sure
58 replies
DTDrizzle Team
Created by Mendy on 10/31/2023 in #help
Smart or Idiotic? The Great BigInt-to-Hash Adventure!
Yeah, it will remain up
58 replies
DTDrizzle Team
Created by Mendy on 10/31/2023 in #help
Smart or Idiotic? The Great BigInt-to-Hash Adventure!
same, I literally only used it for testing out the custom type
58 replies
DTDrizzle Team
Created by Mendy on 10/31/2023 in #help
Smart or Idiotic? The Great BigInt-to-Hash Adventure!
Oh, one drawback to be ware of, is that updates and inserts on drizzle studio will not work. As well as filtering or relation views
58 replies
DTDrizzle Team
Created by Mendy on 10/31/2023 in #help
Smart or Idiotic? The Great BigInt-to-Hash Adventure!
lmk if you get the chance! would love to see the results!
58 replies
DTDrizzle Team
Created by Mendy on 10/31/2023 in #help
Smart or Idiotic? The Great BigInt-to-Hash Adventure!
I can only see 3 possible reasons not to use it: 1. You don't want to leak creation time - ulid will store that (as opposed to uuid or nanoid) 2. You need something shorter for nicer urls 3. 16 bytes is still more then 8 bytes for bigint
58 replies
DTDrizzle Team
Created by Mendy on 10/31/2023 in #help
Smart or Idiotic? The Great BigInt-to-Hash Adventure!
I did some (limited) testing on a 1.3M rows table, and couldn't notice any performence difference
58 replies
DTDrizzle Team
Created by Mendy on 10/31/2023 in #help
Smart or Idiotic? The Great BigInt-to-Hash Adventure!
You pointed me in the right path 🙂
58 replies
DTDrizzle Team
Created by Mendy on 10/31/2023 in #help
Smart or Idiotic? The Great BigInt-to-Hash Adventure!
Yeah it will work. The toDriver will transform it into hex and then binary
58 replies
DTDrizzle Team
Created by Mendy on 10/31/2023 in #help
Smart or Idiotic? The Great BigInt-to-Hash Adventure!
If you're here looking for a solution, see this gist
58 replies
DTDrizzle Team
Created by Mendy on 10/31/2023 in #help
Smart or Idiotic? The Great BigInt-to-Hash Adventure!
NM, solved by letting the DB handle the binary extraction from the hex string
58 replies
DTDrizzle Team
Created by Mendy on 10/31/2023 in #help
Smart or Idiotic? The Great BigInt-to-Hash Adventure!
Do you have any suggestion on how to solve this?
58 replies
DTDrizzle Team
Created by Mendy on 10/31/2023 in #help
Smart or Idiotic? The Great BigInt-to-Hash Adventure!
@Angelelz I've been follwing your direction and I made a ulid custom column to use in my tables:
export const ulid = customType<{
data: string;
notNull: true;
default: false;
driverData: Buffer;
}>({
dataType() {
return "binary(16)";
},
toDriver(value) {
return Buffer.from(ULID.fromCanonical(value).toRaw(), "hex");
},
fromDriver(value) {
return ULID.fromRawTrusted(value.toString("hex")).toCanonical();
},
});
export const ulid = customType<{
data: string;
notNull: true;
default: false;
driverData: Buffer;
}>({
dataType() {
return "binary(16)";
},
toDriver(value) {
return Buffer.from(ULID.fromCanonical(value).toRaw(), "hex");
},
fromDriver(value) {
return ULID.fromRawTrusted(value.toString("hex")).toCanonical();
},
});
For reads and inserts this works prefect, but it won't work on update and deletes as the filter values get parametrized and the db gets the full string instead of the buffer - resulting in no match. Running this:
console.log(
db
.update(testUlid)
.set({ value: "Testing update" })
.where(eq(testUlid.id, "01HEENT3YW02X8Q915QFR4X23W"))
.toSQL(),
);
console.log(
db
.update(testUlid)
.set({ value: "Testing update" })
.where(eq(testUlid.id, "01HEENT3YW02X8Q915QFR4X23W"))
.toSQL(),
);
Results in the following print:
{
sql: 'update `test_ulid` set `value` = ? where `test_ulid`.`id` = ?',
params: [
'Testing update',
<Buffer 01 8b 9d 5d 0f dc 00 ba 8b a4 25 bb f0 4e 88 7c>
]
}
{
sql: 'update `test_ulid` set `value` = ? where `test_ulid`.`id` = ?',
params: [
'Testing update',
<Buffer 01 8b 9d 5d 0f dc 00 ba 8b a4 25 bb f0 4e 88 7c>
]
}
58 replies
DTDrizzle Team
Created by Mendy on 10/31/2023 in #help
Smart or Idiotic? The Great BigInt-to-Hash Adventure!
also, performance aside, ulids have the BEST pronunciation U-Lids
58 replies
DTDrizzle Team
Created by Mendy on 10/31/2023 in #help
Smart or Idiotic? The Great BigInt-to-Hash Adventure!
oh i see
58 replies
DTDrizzle Team
Created by Mendy on 10/31/2023 in #help
Smart or Idiotic? The Great BigInt-to-Hash Adventure!
so where are you generating the ulids?
58 replies