Skip to content

Introduce the concept of functions#91

Merged
brianc merged 4 commits into
brianc:masterfrom
yc662:function
Jun 11, 2013
Merged

Introduce the concept of functions#91
brianc merged 4 commits into
brianc:masterfrom
yc662:function

Conversation

@diwu1989
Copy link
Copy Markdown
Collaborator

@diwu1989 diwu1989 commented Jun 7, 2013

This isn't completely done yet, there's work to be done to load in dialect specific functions. For example, Postgres and MySQL have a ton of math and string functions that aren't available to sqlite.

Columns currently support the concept of aggregate, but it's not as powerful of a concept as function. For example, the column's sum aggregation only sums that particular column, so you can't express sum(columnA.plus(columnB))

@brianc
Copy link
Copy Markdown
Owner

brianc commented Jun 7, 2013

yeah this is definitely awesome. Would be nice to make the function thing 'extensible' so one can easily add other functions. I know with postgres as you enable other addons (such as postGis or plv8) you get more functions. It would be nice to be able to add those functions in user-land code through a public api within node-sql.

@diwu1989
Copy link
Copy Markdown
Collaborator Author

This one is ready to be reviewed, after the Having clause pull request is reviewed. Sql.functionCallCreator will return a function that creates a function call node.

It can be used to create custom functions, ie. ST_AsGeoJSON = Sql.functionCallCreator('ST_AsGeoJSON'), and then use it as ST_AsGeoJSON(table.column).

Comment thread test/function-tests.js
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome

@brianc
Copy link
Copy Markdown
Owner

brianc commented Jun 11, 2013

What do you think about adding the functions to Column.prototype so they can be used without referencing sql.functions? Obviously they can & should stay there (for multi-column functions at the very least) but I do like doing things like

select(user.age.avg()) over select(f.avg(user.age))

Regardless, that can be a future pull request. This bad boy looks good to go!

brianc added a commit that referenced this pull request Jun 11, 2013
Introduce the concept of functions
@brianc brianc merged commit fe73587 into brianc:master Jun 11, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants