NEW IDEAS:
1. To use the "uid" keyword to identify the unique id.
2. To use a PRAGMA to make the engine (UnQLite) to store the uid with
each object when we add them to the collection. This option should be
activated by collection, so in some collections of objects we can
activate the option (using the pragma or in the CREATE COLLECTION
statement) to add the uid to them, and in other collections we may not
use this.
The option could be called:
use_uid -- this one may not be right since the engine may use an uid
anyway, even internally
expose_uid
include_uid
insert_uid
force_uid
or another...
Examples:
--- CREATING THE COLLECTION ----------------------------------
This one will tell the engine to retrieve the uid as a property INSIDE
the objects: (it is only for the retrieval time)
CREATE COLLECTION Contacts OPTIONS insert_uid
These ones doesn't:
CREATE COLLECTION Messages
CREATE COLLECTION SampleValues
--- INSERTING DATA -------------------------------------------
INSERT INTO Contacts VALUE {name: "John", email: "
jo...@email.org"}
INSERT INTO contacts VALUE {name: "Mary", email: "
ma...@email.org"}
INSERT INTO Messages VALUE {user: "John", message: "testing this new
technology"}
INSERT INTO Messages VALUE {type: "note", message: "Hi there!"}
INSERT INTO SampleValues VALUE 55.468
INSERT INTO SampleValues VALUE 47.022
--- RETRIEVING DATA - MODE 1 - PRAGMA return_uid=0 -----------
(Default)
SELECT FROM Contacts
Should return:
[
{uid: 1, name: "John", email: "
jo...@email.org"},
{uid: 2, name: "Mary", email: "
ma...@email.org"}
]
SELECT FROM Messages
Should return:
[
{user: "John", message: "testing this new technology"},
{type: "note", message: "Hi there!"}
]
SELECT FROM SampleValues
Should return:
[
55.468,
47.022
]
--- RETRIEVING DATA - MODE 2 - PRAGMA return_uid=1 -----------
SELECT FROM Contacts
Should return:
[
[1, {uid: 1, name: "John", email: "
jo...@email.org"}],
[2, {uid: 2, name: "Mary", email: "
ma...@email.org"}]
]
SELECT FROM Messages
Should return:
[
[1, {user: "John", message: "testing this new technology"}],
[2, {type: "note", message: "Hi there!"}]
]
SELECT FROM SampleValues
Should return:
[
[1, 55.468],
[2, 47.022]
]
--------------------------------------------------------------
Or we could have 3 values for the PRAGMA:
0 - Never return the uid
1 - Return the uid only inside objects in which the collection option
was specified (default mode)
2 - Always return the uid in a array, being it the first value
--------------------------------------------------------------
Notes:
For the engine, the unique id always exists, linked to each document,
even if it does not expose it (It is what I think).
What we are discussing here is an easy and portable way to retrieve
this value.
The unique id does not need to be stored inside the json object ({})
(note that some 'documents' are arrays and some are simple values), it
can be inserted on the objects only at the retrieval time.
--------------------------------------------------------------
Well, we are open to community opinions.
You're welcome!