File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -107,11 +107,16 @@ export class SqlMacrosPlugin extends StarbasePlugin {
107107 }
108108
109109 try {
110+ // Add semicolon if missing
111+ const normalizedSql = sql . trim ( ) . endsWith ( ';' ) ? sql : `${ sql } ;`
112+
110113 // We allow users to write it `$_exclude` but convert it to `__exclude` so it can be
111114 // parsed with the AST library without throwing an error.
112- sql = sql . replaceAll ( '$_exclude' , '__exclude' )
113-
114- const normalizedQuery = parser . astify ( sql ) [ 0 ]
115+ const preparedSql = normalizedSql . replaceAll (
116+ '$_exclude' ,
117+ '__exclude'
118+ )
119+ const normalizedQuery = parser . astify ( preparedSql ) [ 0 ]
115120
116121 // Only process SELECT statements
117122 if ( normalizedQuery . type !== 'select' ) {
@@ -181,8 +186,8 @@ export class SqlMacrosPlugin extends StarbasePlugin {
181186 } ) )
182187 )
183188
184- // Convert back to SQL
185- return parser . sqlify ( normalizedQuery )
189+ // Convert back to SQL and remove trailing semicolon to maintain original format
190+ return parser . sqlify ( normalizedQuery ) . replace ( / ; $ / , '' )
186191 } catch ( error ) {
187192 console . error ( 'SQL parsing error:' , error )
188193 return sql
You can’t perform that action at this time.
0 commit comments