Answering your first question: for each table you can create a new document, which is much more practical than creating a database for each table.
As for the second question: noSQL database (couchDB, for example) does not have fk or primary key, but the 1:1, 1:N and N:N relationships are still the same as those applied to relational databases. Then your product table, order and ordering:
product:
{
"_id": "100",
"type": "produto",
"nome": "mamão",
"preco": 5.4,
}
request:
{
"_id": "200",
"type": "pedido",
"data": "12/02/2019",
}
product:
{
"_id": "1",
"type": "pedido_produto",
"pedido_id": "200",
"produto_id": "100"
}
And in order for you to be able to fetch all this data in couchDB at once,:
function (doc) {
var pedidoID, produtoID;
if(doc.type == "pedido_produto"){
pedidoID = doc.pedido_id;
produtoID = doc.produto_id;
}
if(doc.type == "pedido"){
emit(pedidoID, {pedido: doc});
}
if(doc.type == "produto"){
emit(produtoID, {produto: doc});
}
}
After saving, so you can consume this view in your application, just make a request via ajax, in your javascript:
function buscarView() {
$.ajax({
url: 'http://127.0.0.1:5984/nome_do_banco/_design/view/_view/view?
include_docs=true',
type: 'GET',
success: function (response) {
//aqui você manipula o resultado
},
error: function (err) {
var t = err.responseText;
console.log("Erro de requisição: " + err.responseText);
}
});
}
Thank you, assuming in mysql I have a table products, one requests and a connecting pedi_products, in the Pouchdb I created a new DB for each table, this escapes from the concepts of Pouchdb, I’m new to the subject, what would be the best way to create this Pouchdb
– Daniel
Creates only an order json and an array of products within the order. The relationship table
pedido_produtos
no need. Like the example above, between person and hobby– LeoCBS
Got it, thanks, but in the case of the same product for multiple orders duplicates the product?
– Daniel
Yes, repeat.. This is one of the side effects of Nosql banks.. This may result in a lack of synchronization between equal products.. It’s up to you to write an application that controls this. If you need a database that you care about
Normalização
data instead of performance/data volume.. recommend using relational databases.. such as Mysql..– LeoCBS