Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate Require plugin? #1611

Open
jimmywarting opened this issue Jan 12, 2023 · 3 comments
Open

Deprecate Require plugin? #1611

jimmywarting opened this issue Jan 12, 2023 · 3 comments

Comments

@jimmywarting
Copy link
Contributor

jimmywarting commented Jan 12, 2023

when fixing sync loading in #1610 (specifically test 298) i tough: isn't it best if developers load plugins themself instead?
it's not so hard to just do something like:

import('path-to-plugin') // when necessary

where the plugin assign itself into alasql

import alasql from 'alasql'

class Echo {
  constructor (params) {
    Object.assign(this, params)
  }

  toString () {
    var s = 'TEST ' + this.expr.toString()
    return s
  }

  execute (databaseid, params, cb) {
    var fn = new Function('params, alasql', 'return ' + this.expr.toJS())
    var res = fn(params, alasql)
    if (cb) res = cb(res)
    return res
  }
}

alasql.yy = Echo

i really do not think it's up to alasql to handle the loading of plugins. what do you think?

@mathiasrw
Copy link
Member

It was a different world back then.

I think we should do this change when all of alasql can also use the import syntax

@jimmywarting
Copy link
Contributor Author

yea... maybe

there is so much eval new Function(code) going on everywhere... would be a bit nicer if alasql didn't have to do that as much. it also breaks some CSP

Not sure if this new Function(...) that's going on everywhere is such a good thing for optimizations. if something is running multiple times then browser are able to optimize a function and also reuse them rather than compiling new javascript JIT

maybe a more compose-able strategy would be better? with iterable helpers you would be able to build some pretty cool stuff. but that is really much in the feature and bleeding edge.

@mathiasrw
Copy link
Member

mathiasrw commented Jan 31, 2023

The new function things are basically the core of how the library works.

It generates the source js for the function to do what you want it to do based on the SQL. The function is cashed so that next time you run that SQL it does not need to run read and understand the SQL.

The only way I see that we can get rid of this is to have alasql act as a build step where the SQL is replaced with an actual function in the final build. This will only work with SQL that is static + parameters so we can replace the alasql call with a call to the actual function currently being cached.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants