Skip to content

Commit

Permalink
Fix issue 2 in #22
Browse files Browse the repository at this point in the history
  • Loading branch information
dsferruzza committed Dec 29, 2015
1 parent 189b5c0 commit 8ad8021
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 2 deletions.
20 changes: 20 additions & 0 deletions dist/simpleSqlParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,19 @@ var operator = alt(
// A number
var number = regex(/[-]?\d+\.?\d*/);

// A duration
var duration = seq(
number,
alt(
string('u'),
string('s'),
string('m'),
string('h'),
string('d'),
string('w')
)
);



/********************************************************************************************
Expand Down Expand Up @@ -896,6 +909,13 @@ var expression = seq(
column: null,
};
}),
duration.map(function(node) {
return {
expression: mkString(node),
table: null,
column: null,
};
}),
number.map(function(node) {
return {
expression: node,
Expand Down
2 changes: 1 addition & 1 deletion dist/simpleSqlParser.min.js

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions dist/simpleSqlParser.withoutDeps.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,19 @@ var operator = alt(
// A number
var number = regex(/[-]?\d+\.?\d*/);

// A duration
var duration = seq(
number,
alt(
string('u'),
string('s'),
string('m'),
string('h'),
string('d'),
string('w')
)
);



/********************************************************************************************
Expand Down Expand Up @@ -364,6 +377,13 @@ var expression = seq(
column: null,
};
}),
duration.map(function(node) {
return {
expression: mkString(node),
table: null,
column: null,
};
}),
number.map(function(node) {
return {
expression: node,
Expand Down
2 changes: 1 addition & 1 deletion dist/simpleSqlParser.withoutDeps.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/sql2ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,19 @@ var operator = alt(
// A number
var number = regex(/[-]?\d+\.?\d*/);

// A duration
var duration = seq(
number,
alt(
string('u'),
string('s'),
string('m'),
string('h'),
string('d'),
string('w')
)
);



/********************************************************************************************
Expand Down Expand Up @@ -211,6 +224,13 @@ var expression = seq(
column: null,
};
}),
duration.map(function(node) {
return {
expression: mkString(node),
table: null,
column: null,
};
}),
number.map(function(node) {
return {
expression: node,
Expand Down
21 changes: 21 additions & 0 deletions tests/tests-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,27 @@ var Select = [
limit: { from: null, nb: 1 },
},
},
{
c: 'Durations',
q: 'SELECT * FROM table WHERE this >= 15m',
a: {
type: 'select',
select: [
{ expression: '*', column: '*', table: null, alias: null, position: { start: 7, end: 8 } },
],
from: [
{ expression: 'table', table: 'table', alias: null, position: { start: 14, end: 19 } },
],
join: [],
where: {
expression: 'this >= 15m',
position: { start: 26, end: 37 },
},
group: [],
order: [],
limit: null,
},
},
{
c: 'Group by',
q: 'SELECT * FROM table GROUP BY col1, MONTH(col2), table.col3',
Expand Down

0 comments on commit 8ad8021

Please sign in to comment.