最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Querying data with JavaScript - Stack Overflow

programmeradmin1浏览0评论

I am currently looking for an intelligent best practice solution for the following problem. Within a web page, I want to make use of data that is currently organised in some MySQL tables.

Problem: I cannot access the database from the webserver, so I am not able to query the data using SQL. Therefore, I thought to transform the data into something JavaScript can handle (e.g. JSON) and perform all the operations on the data on client-side.

Doing SQL-like queries on an object will probably be kind of hard, even if those I need will probably be easy (simple SELECTs). Is there a elegant way to do that? Some nice little javascript library?

Thanks in advance for your ideas.

I am currently looking for an intelligent best practice solution for the following problem. Within a web page, I want to make use of data that is currently organised in some MySQL tables.

Problem: I cannot access the database from the webserver, so I am not able to query the data using SQL. Therefore, I thought to transform the data into something JavaScript can handle (e.g. JSON) and perform all the operations on the data on client-side.

Doing SQL-like queries on an object will probably be kind of hard, even if those I need will probably be easy (simple SELECTs). Is there a elegant way to do that? Some nice little javascript library?

Thanks in advance for your ideas.

Share Improve this question asked Jun 21, 2010 at 8:48 auralbeeauralbee 8,8514 gold badges32 silver badges36 bronze badges 2
  • are you using any databases right now? if yes, what kind of access do you have for it? – Anurag Commented Jun 21, 2010 at 9:04
  • if you cannot access the db then surely you will not able able to access the db with js either? – matpol Commented Jun 21, 2010 at 9:09
Add a ment  | 

2 Answers 2

Reset to default 3

Best practice would (of course) be to put some kind of link (even if not a direct one) between the database and the web server.

For SQL in the browser, though, there's the TrimQuery library, basically a mini-SQL engine written in JavaScript for use on the browser. You would output the "tables" as arays of objects using JSON (as you indicated), and then query it via TrimQuery's SQL support.

But if you can't access the database from the web server, I assume you'll be making a mostly-static copy of the data as an admin procedure and placing it on the webserver. That being the case, you may well be better off determining your usage patterns in your web app and then formatting the data into useful objects as part of the DB->web server copy operation. But if you really need ad-hoc queries into the data, TrimQuery may be a route you could use.

You can try JSINQ:

http://jsinq.codeplex./

which is a Javsascript LINQ implementation. It allows to "query" json object with linq expressions (then in a sql-like way).

发布评论

评论列表(0)

  1. 暂无评论