AlaSQL / alasql

AlaSQL.js - JavaScript SQL database for browser and Node.js. Handles both traditional relational tables and nested JSON data (NoSQL). Export, store, and import data from localStorage, IndexedDB, or Excel.
http://alasql.org
MIT License
7.01k stars 653 forks source link

Avoid exec for new alasql.Database() #329

Open mathiasrw opened 9 years ago

mathiasrw commented 9 years ago

In node I can do this

var alasql = require('alasql');
alasql("SELECT 2+3");

but I cant use same notation if I make a new database

var alasql = require('alasql');
var db = new alasql.Database();
db("SELECT 2+3");                       // TypeError: object is not a function

I will have to use exec for it to work:

var alasql = require('alasql');
var db = new alasql.Database();
db.exec("SELECT 2+3");

would it be possible to avoid the exec for initiated databases so one can reuse code woriginally written for the main alasql database?

agershun commented 9 years ago

@mathiasrw Do you know how to create object-functions in JavaScript?

mathiasrw commented 9 years ago

Function are first class objects in JavaScript so it would be something like

var call = function(x){
  console.log("Calling "+x);
};

call.rescue="911";

call('a friend'); // Calling a friend

call(call.rescue); // Calling 911

Ill make an example using "new" when I get home

agershun commented 9 years ago

But how to use prototypes with functions?

mathiasrw commented 9 years ago

Hmmmm. Im on it...

agershun commented 9 years ago

The problem is located in this file: https://github.com/agershun/alasql/blob/master/src/20database.js

One of the options: we can define functions for each database.

mathiasrw commented 9 years ago

Hmmmmmm. It's not quite.... Hmmmm.

I'll post a stackoverflow question tomorrow

mathiasrw commented 9 years ago

Lets see what http://stackoverflow.com/questions/31290361/new-instance-of-function-with-object-property will give us...

mathiasrw commented 9 years ago

hmmm. still working on this...

mathiasrw commented 8 years ago

Im not finding any solution