MEAN: Doing database queries in Angular Frontend? - javascript

I was wondering if it is somehow possible to do MongoDB No-SQL Queries (or even SQL-queries for sql database) in the Angular frontend, like formulating the query and then sending the query string to the database and getting a subset of values back (e.g. in JSON-format).
Because the problem that I currently have is, that for each data snippet that I need, I have to create a specific route (e.g for one specific graph) and then do my middleware-function for that route that queries for the data in mongodb (e.g by mongodb aggregation framework). And then finally, do a http-request in Angular frontend, eventuelly format the data in javascript in angular and then insert the data in correct format into the appropriate charting-framework (e.g ngx-charts).
E.g. If I would like to filter the data in some chart for specific fields, or do some aggregation etc. on the same chart dynamically, I probably would just query all data from beginning, and then create my own (e.g. filter or other data manipulation) functions in javascript for my chart functions.
I heard there are some ways to do this also in the backend, e.g in Node or MongoDB Aggregation framework, there exists $facet operator that can choose some path for data operation, but I actually don't know how this works together with the Frontend...
Is there not a more direct way to query just the data that I need for a specific component without setting up routing and everything else around?

Related

How to save report filters and making it available for executing and scheduling

I have a use case where I have to Add query params to APIs call, and save it accordingly.
Meaning- I have one report to Add, which gives multiple filters that to be saved. (Some of them are pre-defined and others can be added) which could be saved and it could run to generate report or to schedule it.
How here I am using postgres sql as DB. How can I solve such scenarios, If say saving into db then what's the best way to do such operations? I have a db table where I am storing Report name and descriptions. But how can I add such Filters and Save it? And next time the user just Schedule or generate report with saved filters.
Below are the images for better understanding of the scenario.
The Image of where List displayed of saved reports
The Image where user can Add custom report using available filters.
Not sure the best way to handle such scenarios, where I have to add multiple of filters and save it accordingly.
Can anyone help me here with the approach to handle such things? Like saving in DB or how it could work the best.
Thanks
Edit- Something like JIRA, can save the filters and directly apply it. Something like this.
Assuming that you have control over your web application and that it will translate what users input into SQL queries, just create a data structure that both your UI and your data tier can understand and store it in a table using the JSON or JSONB datatype.

How to have paginated table from database

I've tried a bunch of different React table solutions (reactable, griddle and they all work very similar. You can pass them a set of data and they populate a table. They offer pagination, but not in the since where it's from the source. You can pull 100 Rows from the database, and only show 10 at a time via table pagination. However what if the data is coming from a database / Flux store, how are you supposed to pull what you need from the database?
In the case of a relational database, you would handle the pagination on the database level, if your RDBMS supports it, in the SQL query itself. What you need to do is the following:
Make an AJAX query to the backend with the pagination settings: page size and page number
In the backend, issue your query against the database, using the aforementioned settings, then prepare a JSON result.
Return the results to the frontend, parse it with JSON.parse(), then pass it to the grid component.
In the case of a Flux store, this is a bit more complex as it has different notions than a relational database. The basic principles are the same though, pass parameters to the access component, make a query, return JSON or JavaScript objects.
Pagination in RDMSes
For example, in MySQL (MariaDB) you would do the pagination with the LIMIT qualifier:
SELECT * FROM table LIMIT 20,10
The first parameter sets the first record fetched, the second limits the maximum results. So in this example case, the records between the 20th and 29th are fetched.
Other databases work differently as there is no standard way of doing this. You should look up the documentation of your RDMS.

SpagoBI data set: use javascript to access to MongoDB data base

Since data set in SpagoBI could be created using scripts, I need to connect, query my MongoDB data base using javascript (or Groovy).
I need to use scripts to be able to execute aggregation on the mongoDB data, I can't use aggregation directly on my MongoDB because my data type is String
I dont know how to access my Database using scripts
Any ideas?
You should create a Mongo dataset. The steps to create are:
Step1: Create a Mongo datasource in the administrator console. Notes: the type must be JDBC and the value for Class input field must be "mongo"
JDBC: {unit_host}:{port}/${db}
CLASS: mongo
Step2: now you can create a dataset. The procedure is the same of the query datasets. The difference here is the language.. JS instead of SQL.
Take a look at the SpagoBI wiki in particolar here: http://wiki.spagobi.org/xwiki/bin/view/spagobi_server/data_set#HQueryDataSet28Mongo29
When connecting to mongoDB, you pass auth stuff in the url. Since the scripts lies on the client side, it would be hard to make the connection secure (unless you are talking about backend JavaScript). Anybody would be able to see how to connect to your DB and for instance delete all content.
I would suggest a simple api to interface the database. Then u control the access to what a user can do towards the database.
Or have I misunderstood the scenario?

Storage of Json data to mysql database using php

I am doing a leapmotion webapp on PHP and javascript.it is based on gesture recognition. The values of the leapmotion must be stored into the database and when the corresponding gesture is matched the description of the gesture must be displayed. The values from the leapmotion is converted to JSON format. How can I store the JSON data to the mysql database 5.0.?
The JSON file content is:
{"name":"HA","pose":true,"data":[[{"x":0.16616291409773337,"y":-0.061424365133667,"z":-0.014198921561969446,"stroke":1},{"x":0.058005894163526694,"y":-0.05005164610312531,"z":0.029463953896938344,"stroke":1},{"x":-0.05015112577067998,"y":-0.03867892707258362,"z":0.07312682935584591,"stroke":1},{"x":-0.1583081457048866,"y":-0.02730620804204193,"z":0.1167897048147537,"stroke":1},{"x":-0.2664651656390933,"y":-0.01593348901150024,"z":0.16045258027366138,"stroke":1},{"x":-0.3746221855732999,"y":-0.00456076998095855,"z":0.20411545573256906,"stroke":1},{"x":0.6253778144267002,"y":0.19795540534387668,"z":-0.5697496025117985,"stroke":1}]]}
The error which i get is Syntax error. The work is based on Rob O'leary's leaptrainer.js which can be found on https://github.com/roboleary/LeapTrainer.js/tree/master.
In your situation I'd prefer to do next:
Create separate table for these data. Keys are dependable from your
purposes, but as quick solution just create table with the same
columns names as in your JSON.
Create some model, to communicate with DB. Make there some
methods(like saveMotion, getMotion etc.)
In your php code, use json_decode function, to convert JSON to std
object. Not sure here if you will be able to write std class to db,
but conversion it to array would give you a 100% possibility to do
that.

JSON data querying by breeze

I attempting my first SPA.
It will be a HTML representation of the model of our database structure to give to clients to look through the model and do queries of the database model (not the database data itself).
The requirement is then for no updates and the SPA will be shipped with the release and thus will be offline. Currently it is a static HTML page.
My question is - is there a way to use breeze to query the json file I've created that describes the model? All I've seen are examples of the EntityManager being initialised with a service URL - that will return the data.
Not quite sure I understand the question. What do you mean by (no server)?. Does this mean that you want to bring all of the data down just once and then query it locally?
If the data that you want to query is actually itself metadata then if you describe the structure of the metadata (i.e. metadata of metadata) in Breeze's native metadata format, then you should be able to query the metadata itself via Breeze's EntityQuery.
Probably a little more info would be helpful.
Also, take a look at the Breeze NoDb sample for an example of "custom" metadata construction.

Categories

Resources