Skip to content

Commit 7eb6299

Browse files
Merge branch '143-new-uuid-external-types' into 'main'
Annotations: add new UUID, update docs for external types #143 See merge request objectbox/objectbox-dart!105
2 parents 7278df5 + a8c26e0 commit 7eb6299

File tree

3 files changed

+79
-11
lines changed

3 files changed

+79
-11
lines changed

objectbox/lib/src/annotations.dart

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,13 @@ enum ExternalPropertyType {
498498
/// Encoding: 1:1 binary representation, little endian (16 bytes)
499499
int128,
500500

501+
/// A UUID (Universally Unique Identifier) as defined by RFC 9562.
502+
///
503+
/// ObjectBox uses the UUIDv7 scheme (timestamp + random) to create new UUIDs.
504+
/// UUIDv7 is a good choice for database keys as it's mostly sequential and
505+
/// encodes a timestamp. However, if keys are used externally, consider
506+
/// [uuidV4] for better privacy by not exposing any time information.
507+
///
501508
/// Representing type: ByteVector
502509
///
503510
/// Encoding: 1:1 binary representation (16 bytes)
@@ -510,6 +517,33 @@ enum ExternalPropertyType {
510517
/// Encoding: 1:1 binary representation (16 bytes)
511518
decimal128,
512519

520+
/// UUID represented as a string of 36 characters, e.g.
521+
/// "019571b4-80e3-7516-a5c1-5f1053d23fff".
522+
///
523+
/// For efficient storage, consider the [uuid] type instead, which occupies
524+
/// only 16 bytes (20 bytes less). This type may still be a convenient
525+
/// alternative as the string type is widely supported and more
526+
/// human-readable. In accordance to standards, new UUIDs generated by
527+
/// ObjectBox use lowercase hexadecimal digits.
528+
///
529+
/// Representing type: String
530+
uuidString,
531+
532+
/// A UUID (Universally Unique Identifier) as defined by RFC 9562.
533+
///
534+
/// ObjectBox uses the UUIDv4 scheme (completely random) to create new UUIDs.
535+
///
536+
/// Representing type: ByteVector
537+
///
538+
/// Encoding: 1:1 binary representation (16 bytes)
539+
uuidV4,
540+
541+
/// Like [uuidString], but using the UUIDv4 scheme (completely random) to
542+
/// create new UUID.
543+
///
544+
/// Representing type: String
545+
uuidV4String,
546+
513547
/// A key/value map; e.g. corresponds to a JSON object or a MongoDB document
514548
/// (although not keeping the key order).
515549
///
@@ -550,7 +584,7 @@ enum ExternalPropertyType {
550584
/// A vector (array) of Int128 values.
551585
int128Vector,
552586

553-
/// A vector (array) of Int128 values
587+
/// A vector (array) of Uuid values
554588
uuidVector,
555589

556590
/// The 12-byte ObjectId type in MongoDB.

objectbox/lib/src/native/bindings/objectbox.h

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,8 @@ typedef enum {
479479
/// Value range (normalized vectors): 0.0 - 2.0 (0.0: same direction, 1.0: orthogonal, 2.0: opposite direction)
480480
OBXVectorDistanceType_DotProduct = 3,
481481

482-
OBXVectorDistanceType_Manhattan = 4,
483-
OBXVectorDistanceType_Hamming = 5,
482+
// OBXVectorDistanceType_Manhattan = 4,
483+
// OBXVectorDistanceType_Hamming = 5,
484484

485485
/// For geospatial coordinates aka latitude/longitude pairs.
486486
/// Note, that the vector dimension must be 2, with the latitude being the first element and longitude the second.
@@ -625,16 +625,31 @@ typedef enum {
625625
/// Encoding: 1:1 binary representation, little endian (16 bytes)
626626
OBXExternalPropertyType_Int128 = 100,
627627
// OBXExternalPropertyType_Reserved1 = 101,
628+
/// A UUID (Universally Unique Identifier) as defined by RFC 9562.
629+
/// ObjectBox uses the UUIDv7 scheme (timestamp + random) to create new UUIDs.
630+
/// UUIDv7 is a good choice for database keys as it's mostly sequential and encodes a timestamp.
631+
/// However, if keys are used externally, consider UuidV4 for better privacy by not exposing any time information.
628632
/// Representing type: ByteVector
629633
/// Encoding: 1:1 binary representation (16 bytes)
630634
OBXExternalPropertyType_Uuid = 102,
631635
/// IEEE 754 decimal128 type, e.g. supported by MongoDB
632636
/// Representing type: ByteVector
633637
/// Encoding: 1:1 binary representation (16 bytes)
634638
OBXExternalPropertyType_Decimal128 = 103,
635-
// OBXExternalPropertyType_Reserved2 = 104,
636-
// OBXExternalPropertyType_Reserved3 = 105,
637-
// OBXExternalPropertyType_Reserved4 = 106,
639+
/// UUID represented as a string of 36 characters, e.g. "019571b4-80e3-7516-a5c1-5f1053d23fff".
640+
/// For efficient storage, consider the Uuid type instead, which occupies only 16 bytes (20 bytes less).
641+
/// This type may still be a convenient alternative as the string type is widely supported and more human-readable.
642+
/// In accordance to standards, new UUIDs generated by ObjectBox use lowercase hexadecimal digits.
643+
/// Representing type: String
644+
OBXExternalPropertyType_UuidString = 104,
645+
/// A UUID (Universally Unique Identifier) as defined by RFC 9562.
646+
/// ObjectBox uses the UUIDv4 scheme (completely random) to create new UUIDs.
647+
/// Representing type: ByteVector
648+
/// Encoding: 1:1 binary representation (16 bytes)
649+
OBXExternalPropertyType_UuidV4 = 105,
650+
/// Like UuidString, but using the UUIDv4 scheme (completely random) to create new UUID.
651+
/// Representing type: String
652+
OBXExternalPropertyType_UuidV4String = 106,
638653
/// A key/value map; e.g. corresponds to a JSON object or a MongoDB document (although not keeping the key order).
639654
/// Unlike the Flex type, this must contain a map value (e.g. not a vector or a scalar).
640655
/// Representing type: Flex
@@ -661,7 +676,7 @@ typedef enum {
661676
/// A vector (array) of Int128 values
662677
OBXExternalPropertyType_Int128Vector = 116,
663678
// OBXExternalPropertyType_Reserved9 = 117,
664-
/// A vector (array) of Int128 values
679+
/// A vector (array) of Uuid values
665680
OBXExternalPropertyType_UuidVector = 118,
666681
// OBXExternalPropertyType_Reserved10 = 119,
667682
// OBXExternalPropertyType_Reserved11 = 120,
@@ -2956,4 +2971,4 @@ OBX_C_API obx_err obx_admin_close(OBX_admin* admin);
29562971

29572972
#endif // OBJECTBOX_H
29582973

2959-
/**@}*/ // end of doxygen group
2974+
/**@}*/ // end of doxygen group

objectbox/lib/src/native/bindings/objectbox_c.dart

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10515,8 +10515,6 @@ abstract class OBXVectorDistanceType {
1051510515
/// Because of this, the dot product is often preferred as it performs better.
1051610516
/// Value range (normalized vectors): 0.0 - 2.0 (0.0: same direction, 1.0: orthogonal, 2.0: opposite direction)
1051710517
static const int DotProduct = 3;
10518-
static const int Manhattan = 4;
10519-
static const int Hamming = 5;
1052010518

1052110519
/// For geospatial coordinates aka latitude/longitude pairs.
1052210520
/// Note, that the vector dimension must be 2, with the latitude being the first element and longitude the second.
@@ -10640,6 +10638,10 @@ abstract class OBXExternalPropertyType {
1064010638
/// Encoding: 1:1 binary representation, little endian (16 bytes)
1064110639
static const int Int128 = 100;
1064210640

10641+
/// A UUID (Universally Unique Identifier) as defined by RFC 9562.
10642+
/// ObjectBox uses the UUIDv7 scheme (timestamp + random) to create new UUIDs.
10643+
/// UUIDv7 is a good choice for database keys as it's mostly sequential and encodes a timestamp.
10644+
/// However, if keys are used externally, consider UuidV4 for better privacy by not exposing any time information.
1064310645
/// Representing type: ByteVector
1064410646
/// Encoding: 1:1 binary representation (16 bytes)
1064510647
static const int Uuid = 102;
@@ -10649,6 +10651,23 @@ abstract class OBXExternalPropertyType {
1064910651
/// Encoding: 1:1 binary representation (16 bytes)
1065010652
static const int Decimal128 = 103;
1065110653

10654+
/// UUID represented as a string of 36 characters, e.g. "019571b4-80e3-7516-a5c1-5f1053d23fff".
10655+
/// For efficient storage, consider the Uuid type instead, which occupies only 16 bytes (20 bytes less).
10656+
/// This type may still be a convenient alternative as the string type is widely supported and more human-readable.
10657+
/// In accordance to standards, new UUIDs generated by ObjectBox use lowercase hexadecimal digits.
10658+
/// Representing type: String
10659+
static const int UuidString = 104;
10660+
10661+
/// A UUID (Universally Unique Identifier) as defined by RFC 9562.
10662+
/// ObjectBox uses the UUIDv4 scheme (completely random) to create new UUIDs.
10663+
/// Representing type: ByteVector
10664+
/// Encoding: 1:1 binary representation (16 bytes)
10665+
static const int UuidV4 = 105;
10666+
10667+
/// Like UuidString, but using the UUIDv4 scheme (completely random) to create new UUID.
10668+
/// Representing type: String
10669+
static const int UuidV4String = 106;
10670+
1065210671
/// A key/value map; e.g. corresponds to a JSON object or a MongoDB document (although not keeping the key order).
1065310672
/// Unlike the Flex type, this must contain a map value (e.g. not a vector or a scalar).
1065410673
/// Representing type: Flex
@@ -10676,7 +10695,7 @@ abstract class OBXExternalPropertyType {
1067610695
/// A vector (array) of Int128 values
1067710696
static const int Int128Vector = 116;
1067810697

10679-
/// A vector (array) of Int128 values
10698+
/// A vector (array) of Uuid values
1068010699
static const int UuidVector = 118;
1068110700

1068210701
/// The 12-byte ObjectId type in MongoDB

0 commit comments

Comments
 (0)