happy-sql 2.0.4 → 2.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/ChangeLog CHANGED
@@ -1,3 +1,13 @@
1
+ 2026.08.20, v2.0.6
2
+
3
+ feature:
4
+ - eea70b5 @putout/parser: add source of incorrect sql
5
+
6
+ 2026.08.20, v2.0.5
7
+
8
+ fix:
9
+ - b1cf2b1 happy-sql: parser: where
10
+
1
11
  2026.08.20, v2.0.4
2
12
 
3
13
  fix:
@@ -33,14 +33,16 @@ export const parseSql = (source) => {
33
33
  return convertSource(cst);
34
34
  }
35
35
 
36
- throw Error('Cannot parse SQL');
36
+ throw Error(`Cannot parse SQL: '${source}'`);
37
37
  };
38
38
 
39
+ const isComment = ({text}) => text.startsWith('-- @');
40
+
39
41
  const getSectionName = (leading) => {
40
42
  if (!leading)
41
43
  return null;
42
44
 
43
- const comment = leading.find((c) => c.text.startsWith('-- @'));
45
+ const comment = leading.find(isComment);
44
46
 
45
47
  return comment ? comment.text
46
48
  .slice(2)
@@ -0,0 +1,3 @@
1
+ [
2
+ select(u.id, u.name, from(users as 'u', where(u.active === true))),
3
+ ];
@@ -0,0 +1,3 @@
1
+ SELECT u.id, u.name
2
+ FROM users AS u
3
+ WHERE u.active = true;
@@ -134,6 +134,13 @@ const flattenJoins = (node, joins = []) => {
134
134
  };
135
135
 
136
136
  export const convertFrom = ({expr, whereClause}) => {
137
+ const fromArgs = [];
138
+
139
+ if (whereClause)
140
+ fromArgs.push(callExpression(identifier('where'), [
141
+ convertCondition(whereClause.expr),
142
+ ]));
143
+
137
144
  if (expr.type === 'join_expr') {
138
145
  const parts = flattenJoins(expr);
139
146
  return callExpression(identifier('from'), parts);
@@ -142,16 +149,11 @@ export const convertFrom = ({expr, whereClause}) => {
142
149
  if (expr.type === 'alias')
143
150
  return callExpression(identifier('from'), [
144
151
  convertAlias(expr),
152
+ ...fromArgs,
145
153
  ]);
146
154
 
147
- const fromArgs = [
155
+ return callExpression(identifier('from'), [
148
156
  identifier(expr.name),
149
- ];
150
-
151
- if (whereClause)
152
- fromArgs.push(callExpression(identifier('where'), [
153
- convertCondition(whereClause.expr),
154
- ]));
155
-
156
- return callExpression(identifier('from'), fromArgs);
157
+ ...fromArgs,
158
+ ]);
157
159
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "happy-sql",
3
- "version": "2.0.4",
3
+ "version": "2.0.6",
4
4
  "type": "module",
5
5
  "description": "sql to js ast parser and printer",
6
6
  "exports": {