How to generate UUID with angular 2?
It’s downloaded as a part of Angular’s dependency, use it like: import { v4 as uuid } from ‘uuid’; @Component(..) export class AppComponent { console.log(‘new uid: ‘, uuid()); }
It’s downloaded as a part of Angular’s dependency, use it like: import { v4 as uuid } from ‘uuid’; @Component(..) export class AppComponent { console.log(‘new uid: ‘, uuid()); }
Just in case, there is also boost::uuids::to_string, that works as follows: #include <boost/uuid/uuid.hpp> #include <boost/uuid/uuid_io.hpp> boost::uuids::uuid a = …; const std::string tmp = boost::uuids::to_string(a); const char* value = tmp.c_str();
MySQL 5.7, 8.0.12 and older MySQL as of 5.7 or 8.0.12 does not support using a function or expression as the default value of a column. The DEFAULT value clause in a data type specification indicates a default value for a column. With one exception, the default value must be a constant; it cannot be … Read more
The following would create the result I was after: SELECT LOWER(CONCAT( SUBSTR(HEX(uuid), 1, 8), ‘-‘, SUBSTR(HEX(uuid), 9, 4), ‘-‘, SUBSTR(HEX(uuid), 13, 4), ‘-‘, SUBSTR(HEX(uuid), 17, 4), ‘-‘, SUBSTR(HEX(uuid), 21) )) FROM foo;
This will do, if you’re using modern C++. #include <random> #include <sstream> namespace uuid { static std::random_device rd; static std::mt19937 gen(rd()); static std::uniform_int_distribution<> dis(0, 15); static std::uniform_int_distribution<> dis2(8, 11); std::string generate_uuid_v4() { std::stringstream ss; int i; ss << std::hex; for (i = 0; i < 8; i++) { ss << dis(gen); } ss << “-“; … Read more
public class UuidUtils { public static UUID asUuid(byte[] bytes) { ByteBuffer bb = ByteBuffer.wrap(bytes); long firstLong = bb.getLong(); long secondLong = bb.getLong(); return new UUID(firstLong, secondLong); } public static byte[] asBytes(UUID uuid) { ByteBuffer bb = ByteBuffer.wrap(new byte[16]); bb.putLong(uuid.getMostSignificantBits()); bb.putLong(uuid.getLeastSignificantBits()); return bb.array(); } } @Test public void verifyUUIDBytesCanBeReconstructedBackToOriginalUUID() { UUID u = UUID.randomUUID(); byte[] uBytes … Read more
I figure I might as well add my solution here, for posterity. None of the above was exactly what I needed: jest.mock(‘uuid’, () => ({ v4: () => ‘123456789’ })); By the way, using a variable instead of ‘123456789’ breaks it. This should be mocked where we have the imports and it does not require … Read more
Try: @PrimaryGeneratedColumn(“uuid”) id: string; Also, if you don’t need a primary column, but need to generate uuid sequence, you can try this: @Column() @Generated(“uuid”) uuid: string;
You could create a wrapper around a string and pass that around: class GUID { private str: string; constructor(str?: string) { this.str = str || GUID.getNewGUIDString(); } toString() { return this.str; } private static getNewGUIDString() { // your favourite guid generation function could go here // ex: http://stackoverflow.com/a/8809472/188246 let d = new Date().getTime(); if (window.performance … Read more
In PostgresSQL’s SQL grammar Using concat(UUID,”) returns a text result. Using uuid(text) returns a UUID result.