-5

Weather javascript is a database enabled language?

Can javascript be used as a language to connect and query the database? If yes why and if no why? Please explain in detail?

Cristik
  • 30,989
  • 25
  • 91
  • 127
  • What do you mean by "database enabled language"? – Cristik May 03 '15 at 07:59
  • What kind of database? `var data = { name: "Dave" }` - that could be considered a database. – CodingIntrigue May 03 '15 at 08:03
  • Possible duplicate of this: http://stackoverflow.com/questions/857670/how-to-connect-to-sql-server-database-from-javascript – DigitalDouble May 03 '15 at 08:04
  • Seriously, people, the question is quite clear and you're messing around here... OP asks if you could do some commonly used database queries to extract data or do other stuff in the DB. E.g. `SELECT * FROM MyData`. I have no experience in using DBs, but somehow I understood the question, so I guess you too... – ZygD May 03 '15 at 08:07
  • 1
    @ZygD It's really not. The word `database` is painfully vague. You referenced SQL - what kind of SQL would that be? MySQL, MSSQL? Who said they wanted SQL? Maybe they meant Mongo? Perhaps another NoSQL provider? – CodingIntrigue May 03 '15 at 08:09
  • @Cristik :I want to know can we use database connectivity in javascript as we do in java by importing packages like java.sql? – user3381933 May 03 '15 at 10:41

1 Answers1

5

Theoretically any programming language can be used to connect to a database, as long as it has the proper db libraries that the developer can use to connect to the DBMS.

In particularly javascript has some limitations (like servers it can connect to, resources from PC that can access), when run inside a web browser container, limitations that are not part of the language itself. Node.js on the other hand doesn't have these limitations.

Most of the times you'll need a proxy between your javascript ajax calls and the actual database, because:

  • on one hand to not publicly expose the db credentials and also as secured databases don't allow remote connections,
  • and on the other hand as many DBMS require a binary communication protocol, which is not feasible to be implemented in javascript (there are DBMS which allow a json-based communication though)

My recommendation: implement the DB connect and query logic on the server-side part, and build a (RESTful) API to indirectly access the database this way. This also gives you control over what a logged in user can do with the database.

Cristik
  • 30,989
  • 25
  • 91
  • 127