From 4c82bffb6e37e363c60d7157c4d4645a223d354e Mon Sep 17 00:00:00 2001 From: Maria Date: Thu, 23 May 2019 23:08:02 +0300 Subject: [PATCH 1/3] Added ECMAScript proposal --- proposal.md | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 proposal.md diff --git a/proposal.md b/proposal.md new file mode 100644 index 0000000..d1b2792 --- /dev/null +++ b/proposal.md @@ -0,0 +1,106 @@ +# ECMAScript proposal: Get and modify object data by queries +- [Motivation](#motivation) +- [High-level API](#high-level-api) +- [FAQ](#faq) + +## Motivation + +You can have the ability to find and store data in the localStorage or in a created array by writing some queries. You can use a part of a database funtionality in JS to make the way of retrieving and saving data more comfortable. Queries are lazily evaluated to avoid testing all data when it's not necessary. + +## High-level API + +```js + +const friends = [ + {"id": 1, "gender": "M", "first": "Vlad", "last": "Ivanov", "city": "Moscow", "country": "Russia"}, + {"id": 2, "gender": "M", "first": "Alex", "last": "Petrov", "city": "Saint-Petersburg", "country": "Russia"}, + {"id": 3, "gender": "M", "first": "Darsy", "last": "Zelt", "city": "Los-Angeles", "country": "USA"}, + {"id": 4, "gender": "F", "first": "Olga", "last": "Orlova", "city": "Ufa", "country": "Russia"} +]; // Initialize the array + +/* Make simple queries */ +friends.where({"last": "Ivanov"}); // Find by whole last name + +friends.where({"last": "Ivanov", "first": "Alex"}); // Find by first and last name + +friends.like({"last": "Ze"}); // Find by a part of last name + +friends.distinct("country"); // Get an array of distinct countries + +friends.where({"gender": "M"}).first(); // Get first result from selection + +/* Make CRUD operations */ +friends.where({"last": "Ivanov"}).update({"city":"Saint-Petersburg"}); // Update data + +friends.insert({"id": 5, "gender": "M", "first": "Nikolay", "last": "Basin", "city": "Washington", "country": "USA"}); // Insert a row + +friends.removeRow({"id": 5}); // Remove a row + +const newFriends = [ + {"id": 6, "gender": "M", "first": "Ivan", "last": "Ivanov-Petrov", "city": "Moscow", "country": "Russia"}, + {"id": 7, "gender": "M", "first": "Petr", "last": "Petrov-Ivanov", "city": "Saint-Petersburg", "country": "Russia"}, + {"id": 8, "gender": "M", "first": "John", "last": "Rhom", "city": "Los-Angeles", "country": "USA"}, + {"id": 9, "gender": "F", "first": "Irina", "last": "Orlova", "city": "Ufa", "country": "Russia"} +]; // Initialize new array + +friends.merge(newFriends); // Merge two (or more) arrays into "friends" array + + +/* Work with localStorage */ +friends.persist(); // Save in the localStorage with hash key (e. g. "767tgjbg868g") +/* In the localStorage: + Key | value +"767tgjbg868g" | { + "name": "friends", + "dateTime": 1558452419340, + "data": [ + {"id": 1, "gender": "M", "first": "Vlad", "last": "Ivanov", "city": "Moscow", "country": "Russia"}, + {"id": 2, "gender": "M", "first": "Alex", "last": "Petrov", "city": "Saint-Petersburg", "country": "Russia"}, + {"id": 3, "gender": "M", "first": "Darsy", "last": "Zelt", "city": "Los-Angeles", "country": "USA"}, + {"id": 4, "gender": "F", "first": "Olga", "last": "Orlova", "city": "Ufa", "country": "Russia"} + ] + } +*/ + +friends.persist("lovelyFriends"); // Save in the localStorage with hash key (e. g. "767tgjbg868g") and with name "lovelyFriends" +/* In the localStorage: + Key | value +"767tgjbg868g" | { + "name": "lovelyFriends", + "dateTime": 1558452419340, + "data": [ + {"id": 1, "gender": "M", "first": "Vlad", "last": "Ivanov", "city": "Moscow", "country": "Russia"}, + {"id": 2, "gender": "M", "first": "Alex", "last": "Petrov", "city": "Saint-Petersburg", "country": "Russia"}, + {"id": 3, "gender": "M", "first": "Darsy", "last": "Zelt", "city": "Los-Angeles", "country": "USA"}, + {"id": 4, "gender": "F", "first": "Olga", "last": "Orlova", "city": "Ufa", "country": "Russia"} + ] + } +*/ + +getFromLocalStorage({"name": "friends"}); // Get all results from localStorage with name "friends" + +const superFriends = getFromLocalStorage({"name": "friends"}).lastByTime(); // Get last in time result from localStorage with name "friends" + +superFriends.removeFromLocalStorage(); // Remove from the localStorage + + +/* Make chaining */ +friends.where({"gender": "M"}) + .distinct("country") + .persist("countries") + .collect(); // Terminate a chaining with the method 'collect()' + + +/* Support promises */ +load("http://some-example-fruits.com") // Get selected data from promise + .where({name: "apple"}) + .like({color: "red"}) + .catch(e => console.error(e)) + .collect(); + +``` + +### FAQ +#### Does this syntax support all database operations? + +No, some of operations aren't supported because of their uselessness in this context (e. g. inner join or outer join). From aa07afa088a57ff94bc3016c2792039256a84ee1 Mon Sep 17 00:00:00 2001 From: Maria Date: Thu, 23 May 2019 23:37:10 +0300 Subject: [PATCH 2/3] Update proposal.md --- proposal.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proposal.md b/proposal.md index d1b2792..fdeb6ef 100644 --- a/proposal.md +++ b/proposal.md @@ -1,11 +1,11 @@ -# ECMAScript proposal: Get and modify object data by queries +# ECMAScript proposal: ETL API for JavaScript - [Motivation](#motivation) - [High-level API](#high-level-api) - [FAQ](#faq) ## Motivation -You can have the ability to find and store data in the localStorage or in a created array by writing some queries. You can use a part of a database funtionality in JS to make the way of retrieving and saving data more comfortable. Queries are lazily evaluated to avoid testing all data when it's not necessary. +You can have the ability to build ETL process, which allows you transfer and process data to the localStorage or to a created array. You can use a part of a pipeline funtionality in JS to make the way of retrieving and saving data more comfortable. These methods are lazily evaluated to avoid intermediate calculations when it's not necessary. ## High-level API From 13c2c9708614c7ec59f3d82703d00527e995f7fa Mon Sep 17 00:00:00 2001 From: Maria Date: Thu, 23 May 2019 23:43:33 +0300 Subject: [PATCH 3/3] Update proposal.md --- proposal.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proposal.md b/proposal.md index fdeb6ef..5701f75 100644 --- a/proposal.md +++ b/proposal.md @@ -5,7 +5,7 @@ ## Motivation -You can have the ability to build ETL process, which allows you transfer and process data to the localStorage or to a created array. You can use a part of a pipeline funtionality in JS to make the way of retrieving and saving data more comfortable. These methods are lazily evaluated to avoid intermediate calculations when it's not necessary. +You can have the ability to build ETL process, which allows you transfer and process data to the localStorage or to a created array. You can use a part of a pipeline funсtionality in JS to make the way of retrieving and saving data more comfortable. These methods are lazily evaluated to avoid intermediate calculations when it's not necessary. Support different web sources: localStorage, REST services, arrays in-memory. ## High-level API