I am new to Datastore and I am trying to create a simple app that tracks books borrowing.
I would like the DB schema to be as follows:
books:
book_id
name:
borrowing:
timestamp:
user_id
firstname
email
users:
name:
borrowed:
timestamp:
book_id
I am using the console to configure the DB.
I have defined two Kinds: Books
and User
Business logic:
- 1 book can be borrowed by n users.
- 1 user can borrow n books
Basically, when a user borrows a book I want the two following inserts to occur:
- a new borrowing entry is appended to the book entity of type Book, with the current timestamp as key and user_id, firstname and email as properties
- a new borrowed entry is appended to the user entity of ty User, with the current timestamp as key and the book_id as property
How can I achieve this (managing nested lists children) with Datastore? Through embedded entities? Parent ref?
Here is an example of what I expect:
{
"books": {
"book1": {
"name": "book number 1",
"borrowing": {
"1234567890": {
"user_id": "user1",
"firstname": "john",
"email": "john@example.com"
},
"2234567890": {
"user_id": "user2",
"firstname": "robin",
"email": "robin@example.com"
}
}
}
...
},
"users": {
"user1": {
"firstname": "robin",
"email": "robin@example.com",
"borrowed": {
"1234567890": {
"book_id": "book1"
},
"3247829398": {
"book_id": "book99"
}
}
},
...
}
}