This is possibly a broad question:
I've been teaching myself how to program for the last year. I've learned how to create simple websites using HTML, CSS, and JavaScript. I've also learned how to create simple databases using PostgreSQL. I need help figuring out how to connect (API) the front end and the back end.
A friend suggested I learn how to use AWS RDS so I've already created a PostgreSQL DB instance there (tutorial). I've also connected to my DB using pgAdmin 4 using this tutorial.
What I would like to do is have my front end take in a number as the user's input and "submit" (POST) that value in the DB. Every time the user submits a new value, the new value is saved in the DB and the cumulative values of everything POSTed is returned to the front end for the user to see.
I know this project is a bit asinine but its a start. I can't find any more links on the internet to teach myself how to do this. If you have tips or resources (web links) to help me accomplish this, I would be really grateful.
Side note - I've also been studying python for the last year if that helps.
First, connect to the database like so:
$c1 = new PDO('pgsql:host=THERDSURL;user=THEDBUSERNAME;dbname=THEDATABASENAME;password=THEPASSWORD;connect_timeout=500',null,null);
Then start a new query like so:
$statement=$c1->prepare("select * from mytable");
Then execute it:
$statement->execute();
then loop through the results like so:
while($row=$statement->fetch());
{
var_dump($row)
}
it will vary a little depending on whether you're getting data or inserting data, but begin by learning how to get (select) data. Create a table using a GUI of some kind and learn how to query it programatically.
NOTE: Most people use a library of some kind to make the querying both more powerful and less complicated.. This code is in PHP, but a very similar process is done in many languages.
Note2: do not try to do any of this in javascript that's embedded in html or that's running on a client machine. Connecting to postgres using embeded javascript is not the normal way to go about doing this. Usually people use a language like PHP, Python, Java, etc.. and that's usually running on the server-- and although you can use javascript that runs on the server, I wanted to warn you about this because newer developers might not realize that javascript running on the server vs the browser has completely different capabilities where this is concerned.
Related
So I know the JDBC Rivers plugin is deprecated so even though it is being used I'd ideally not want to look at using something that is no longer supported.
However I have a few tables in a Postgres database with values that I need to be able to search in a Kibana view. Im new to the ELK stack but i've been messing around with some of their samples to get familiar.
I've seen some mentions of using Stored Procedures/Triggers from Postgres to send to Logstash. Although im not sure if this is the best way. Im not a developer but a QA so my coding skills are "ok" as im used to writing automation tests/etc...
What would be the best way to do this? I would want to probably capture updates to these tables (probably new inserts or updates) OR be able to poll the data every X period of time (30s or something). Lets pretend it's for a weather station and the tables contain humidity data from different weather sensors.
I'd want to be able to search in a Kibana view the Values/Station ID/etc...
Is this doable? Is there maybe a better way than using Triggers/Stored procedures?
I ended up using the JDBC driver and following https://www.elastic.co/blog/logstash-jdbc-input-plugin to get it moving and working (Which it does move). But it was a lot of setup for anyone that may see this answer.
Express js uses qs parser to parse query strings into objects. Is there a lib out there for use on front-end applications that does the reverse? I would love to be able to write a mongo db query on the front end in object form and have it parsed automatically into the format qs parser is expecting right before the request is made.
I would love to be able to write a mongo db query on the front end in object form
You should absolutely not do this unless you're OK with essentially giving any user of your web app an open shell to do whatever they want to your database.
But with that said, I found this in bower.io:
https://github.com/fernandofleury/query-object
More here:
http://bower.io/search/?q=qs
Stumbled upon this question, I suppose you don't need it anymore, but I hope this helps other users who end up here:
Meet graphQL. It's an open standard, which lets you query backend api's in a flexible manner.
Mongodb even supports it out of the box and it is permission based, so no worries about frontend users hacking into your database (you should of course properly configure those permissions to limit access to specific resources).
Read more on https://docs.mongodb.com/realm/graphql
I am working on a web application for a client that uses a postgresql database. I want the client to be able to go to a certain area of the site where the data from the database is displayed in graph form (for example, sales figures over a 6 month period). Is there a plugin I could use for this (I don't have any experience of this, so an easy one, or one with tutorials available would be great). I had a look at BIRT, which says it has a web based option but I couldn't really figure it out. I don't want the client to have to download and go through another program, I just want them to go to a url within their site, and it's all just presented to them there and then.
Any sort of pointers in the right direction would be greatly appreciated.
Thank you.
HighCharts, at http://www.highcharts.com/, works well for this case -- I use it fairly often. It supports Ajax data feeds in JSON format, so you can write an endpoint which returns the JSON representing the data from Postgres and which gets called from a JavaScript function which creates the graphs using that data (you would place that call in a ready function).
Also, if you're using Postgres 9.3 or higher, it supports JSON natively, so you can do the JSON conversion in the SQL query itself, as opposed to post-processing the results in your Python or other backend code.
Highcharts is reasonably flexible and allows for a variety of nice-looking, functional charts and graphs. If you want to get much fanicer, d3 may be worth a look. These are some the types of graphs/charts it can do: https://github.com/mbostock/d3/wiki/Gallery
I have not used d3 myself, however.
For the scenario you described above, Highcharts seems like it would work just fine.
It's been a while, and a lot has happened since 2016. There is now ChartJS as well - http://chartjs.org/, for example, which is easier to use than HighCharts and very flexible (I've used both).
What they both don't do is dynamic data. If you want that your client decides which data he wants to watch - that part you need to write yourself.
Im in the start up phase of creating an internal system based on PHP and MongoDB. The users of this system are Javascript programmers and would like to be able to make custom queries to the Mongo database from a frontend gui with arbitrary Mongo shell queries. Of course this would not be a problem at all if I forced them to to write the queries with proper PHP arrays etc, but i would definitely like to avoid this.
I am not quite sure how to approach a feature like this without writing some advanced methods being able to restructure the queries to proper formated arrays that can be used in MongoClient PHP. One approach would be making use of the i.e. MongoDB::execute() method and run the javascript on the database server - a method i don't fancy at all.
Im kindly asking if you have any ideas on how to achieve the requested functionalities to some extend.
Thank you in advance.
Are you looking for something like this : http://rockmongo.com/ ?
My App needs to connect to and grab data from a MySQL database sitting on a server. I've successfully interfaced with local SQLITE databases in my Apps, but this is the first time I've had to interface with a remote MySQL database.
I understand this process involves:
1) the iPhone App sending this request to the server
2) some sort of API gets executed and it does the actual "talking" to the Database on the server, and then it returns the query results as XML (or JSON.)
3) the iPhone then parses the returned information and uses it however it needs to.
What I need help with is step # 2 - the API. I don't know PHP, I don't know PERL - do I really have to learn one of these just to write an API? I thought that this iphone-to-remote-MySQL task would be so commonplace that such API's would already be out there, available freely - but I'm not really seeing anything.
I know Objective-C really well - but should I be using XML or JSON for this? Should I be learning PERL or PHP?
any tips or advice would be highly appreciated.
It's hard to give you a definite answer without knowing more precisely what you are looking at, but it sounds like your web service/API part should be quite light. In this case, it should be quite easy to write it in any language. If you know Objective-C well, it should be very easy to pick up some PHP or Ruby.
You mention PHP and Perl. The good thing I see with PHP is that it's available on any hosting service. For instance, with PHP you can make MySQL queries in a few lines of code.
Otherwise, if the web service lives on a machine that you own or if you have more flexibility, it might be easier to write something using Ruby and a small framework like Sinatra.
Regarding using XML or JSON to serialize the data, this will depend on what type of data your API returns. Generally, JSON will be much simpler and the support is good on both side:
- With Ruby, you can see how easy it is to use JSON here: http://flori.github.com/json/
- With Objective-C, you would use NSJSONSerialization available starting with iOS5.
Well you can talk to remote MySQL server using Objective C client directly from iphone
as show here