sqb-serializer-oracle
Advanced tools
Comparing version 0.1.0 to 0.2.0
{ | ||
"name": "sqb-serializer-oracle", | ||
"description": "SQB serialization plugin for Oracle database", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"author": "Panates Ltd.", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
@@ -26,20 +26,28 @@ /* SQB Oracle Serializer Plugin | ||
const limit = this.statement._limit || 0; | ||
const offset = obj._offset || 0; | ||
const a = obj._alias; | ||
const offset = Math.max((obj._offset || 0) - 1, 0); | ||
if (limit || offset) { | ||
const order = this.statement._orderby; | ||
if (offset || (order && order.length)) { | ||
out = 'select ' + (a ? a + '.' : '') + '* from (\n\t' + | ||
'select /*+ first_rows(' + (limit || 100) + | ||
') */ rownum row$number, t.* from (\n\t' + | ||
out + '\n\b' + | ||
') t' + (limit ? ' where rownum <= ' + (limit + offset - 1) : '') + | ||
'\n\b)' + (a ? ' ' + a : ''); | ||
if (this.config.serverVersion >= 12) { | ||
if (offset) | ||
out += ' where row$number >= ' + (offset); | ||
out += (offset ? '\nOFFSET ' + offset + ' ROWS' : '') + | ||
(limit ? ' FETCH NEXT ' + limit + ' ROWS ONLY' : ''); | ||
else out += (limit ? '\nFETCH FIRST ' + limit + ' ROWS ONLY' : ''); | ||
} else { | ||
out = 'select ' + (a ? a + '.' : '') + '* from (\n\t' + | ||
out + '\n\b' + | ||
') where rownum <= ' + limit; | ||
const a = obj._alias; | ||
const order = this.statement._orderby; | ||
if (offset || (order && order.length)) { | ||
out = 'select ' + (a ? a + '.' : '') + '* from (\n\t' + | ||
'select /*+ first_rows(' + (limit || 100) + | ||
') */ rownum row$number, t.* from (\n\t' + | ||
out + '\n\b' + | ||
') t' + | ||
(limit ? ' where rownum <= ' + (limit + offset) : '') + | ||
'\n\b)' + (a ? ' ' + a : ''); | ||
if (offset) | ||
out += ' where row$number >= ' + (offset + 1); | ||
} else { | ||
out = 'select ' + (a ? a + '.' : '') + '* from (\n\t' + | ||
out + '\n\b' + | ||
') where rownum <= ' + limit; | ||
} | ||
} | ||
@@ -46,0 +54,0 @@ } |
6500
83