-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/hemedani/funql into main
- Loading branch information
Showing
9 changed files
with
324 additions
and
61 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# **Lesan** Specification: | ||
|
||
> Standardizing the output through the use of "data modeling" based on NoSQL | ||
The following documentation attempts to clarify the motivation behind the "Lesan". | ||
|
||
## Design Philosophy: | ||
|
||
The inital concept of "Lesan" was first conceived during a project using GraphQL. As you may already know, GraphQL deals with the data in a graph structure with a view to solving some limitation in REST APIs, namely "overfetch" and "underfetch". | ||
|
||
The first design decision for "Lesan" was to introduce the idea of using functions/methods that we can declare to selectively return the amount and type of data. | ||
|
||
Using "NoSQL" documents as the underpinning way to store large amount of data, a few utility interface models are specified for each entity in our model domain. | ||
|
||
- inRelation: In order to minimize the number of queries to obtain a piece of information, some data are embedded in a document, for instance, a user can be saved within a blog document. | ||
- outRelation: A document within a collection has the capacity to store 16MB of data, thus, in a specific context the data that you have chosen to embed might grow large enough to exceed this number. | ||
To proactively design our program to deal with this situation, a part of the data is stored within the document in the form of "paginate" as an embedded collection of data. | ||
The rationale behind this decision was that, in a example of a blog with comments, more often than not only a piece of the large number of comments is needed, so by stroing only a chunk of this data within a blog, we prevent unnecessary queries to retireve all the comments. | ||
-pureRelation: These are the properties that are native to a model | ||
|
||
## Performance: | ||
|
||
Due to the fact that the number of queries are minimized to the least number possible and having information stored as embedded piece of information, the number of aggregate queries are greatly reduced. | ||
|
||
To shed some light on why this can happen, let's compare the number of queries for a real case scnenario. | ||
|
||
In the first step, we have 1 query for both SQL and NoSQL, as the relations expands the number of queries in a SQL database increases dramatically; however, in our design we keep the queries in control by retrieving information in the most optimal fashion. | ||
|
||
### Updating documents | ||
|
||
Updating a field of a document could result in a cascade of updates in different relationships between different entities in our models. For instance, if a user decides to updates his name on his profile, his name must get updated in hundreds if not thousands of documents. In order to optimize this heavy and resouce-consuming operation a **\*Query Queue** is incorporated in "Lesan" which is capable of merging the relationship to make optimal update queries in the system. |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import React, { useEffect, useRef, useState } from "react"; | ||
import JSONPretty from "react-json-pretty"; | ||
import "react-json-pretty/themes/monikai.css"; | ||
import styled from "styled-components"; | ||
import ModalBox from "./Modalbox"; | ||
|
||
interface Props { | ||
setHistory: any; | ||
history: boolean; | ||
} | ||
const History: React.FC<Props> = ({ history, setHistory }) => { | ||
const scroll: any = useRef(null); | ||
|
||
const [itemHistory, setItemHistory] = useState( | ||
localStorage.getItem("history") && | ||
JSON.parse(localStorage.getItem("history")!) | ||
); | ||
useEffect(() => { | ||
console.log("i call", JSON.parse(localStorage.getItem("history")!)); | ||
setItemHistory(JSON.parse(localStorage.getItem("history")!)); | ||
}, [localStorage.getItem("history")]); | ||
// setItemHistory( | ||
// localStorage.getItem("history") && | ||
// JSON.parse(localStorage.getItem("history")!) | ||
// ); | ||
// console.log(itemHistory, JSON.parse(localStorage.getItem("history")!)); | ||
const Delete = (item: number) => { | ||
setItemHistory( | ||
itemHistory.filter((value: any) => itemHistory[item] !== value) | ||
); | ||
}; | ||
|
||
return ( | ||
<ModalBox open={history} setOpen={setHistory} textHeader="History"> | ||
<ContHistory ref={scroll}> | ||
<Tag | ||
onClick={() => { | ||
setItemHistory([]); | ||
localStorage.removeItem("history"); | ||
}} | ||
> | ||
Clear All | ||
</Tag> | ||
<Body> | ||
{itemHistory && | ||
itemHistory.map((item: any, index: number) => { | ||
return ( | ||
<Item> | ||
<Close onClick={() => Delete(index)}>×</Close> | ||
<ItemBody> | ||
<Side> | ||
<JSONPretty | ||
id="json-pretty-history" | ||
data={item.request} | ||
></JSONPretty> | ||
</Side> | ||
<Side> | ||
<JSONPretty | ||
id="json-pretty-history" | ||
data={item.response} | ||
></JSONPretty> | ||
</Side> | ||
</ItemBody> | ||
</Item> | ||
); | ||
})} | ||
</Body> | ||
</ContHistory> | ||
</ModalBox> | ||
); | ||
}; | ||
|
||
export default History; | ||
const ContHistory = styled.div` | ||
overflow-x: hidden; | ||
height: 100%; | ||
`; | ||
const Body = styled.div` | ||
padding: 0 0 1rem 0; | ||
display: flex; | ||
overflow-x: auto; | ||
height: 85%; | ||
`; | ||
|
||
const Item = styled.div` | ||
display: flex; | ||
border: rgb(119, 82, 190) solid 0.1rem; | ||
min-width: 35rem; | ||
border-radius: 0.5rem; | ||
flex-direction: column; | ||
margin-right: 1.5rem; | ||
`; | ||
const ItemBody = styled.div` | ||
display: flex; | ||
height: 93%; | ||
`; | ||
const Side = styled.div` | ||
display: flex; | ||
margin: 0.5rem; | ||
border-radius: 0.5rem; | ||
overflow-x: auto; | ||
flex: 1; | ||
`; | ||
const Close = styled.span` | ||
text-align: start; | ||
font-size: 1.5rem; | ||
padding-left: 0.5rem; | ||
`; | ||
|
||
const Tag = styled.p` | ||
color: white; | ||
width: 6rem; | ||
font-size: 0.9rem; | ||
padding: 0.3rem 0; | ||
margin: 0.5rem; | ||
text-align: center; | ||
border-radius: 0.2rem; | ||
background-color: #ffb1b1; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.