Using UUID as primary key
Hello,
Comming back to Cache after some long gap. Is it possible to use UUID as primary key while creing a Persistant class (Not using the default numerical ID)?
and creating the relationships also using UUID?
Comments
You can use whatever you want, just remember about some caveats, like issue with bitslice/bitmap indexes, which requires numerical ID
I would recommend using just a Unique Index for the UUID field and use it, it should cover most of the needs.
What is the datatype for UUID?
id this one HS.FHIR.vSTU3.Model.Datatype.Uuid?
How we can autogenerate UUID when creating an object?
##class(%SYS.System).InstanceGUID()
This function returning a same UUID!!!
InstanceGUID returns the GUID of the instance, which does not change. $system.Util.CreateGUID() will generate a GUID. See
https://docs.intersystems.com/iris20223/csp/documatic/%25CSP.Documatic…
Personally I'd rather use a default numeric ID and if needed an additional UUID/GUID unique property.
To implement what you asked you can use something like:
Class My.TestClass Extends%Persistent
{
Property PrimaryUUID As%String [ InitialExpression = {$system.Util.CreateGUID()} ];Property MyOtherData As%String;
Index PrimaryUUIDIndex On PrimaryUUID [ IdKey, Unique ];
}
In this way the primary key (PrimaryUUID) is automatically assigned, no need to set it manually, in SQL is mapped as ID (as well as PrimaryUUID).
Enrico
Thank you very much. desiging a system where data can be merged from differant local DBs. by having UUID there wont be any conflict in primary keys when merging!