Skip to content

Commit f809ad2

Browse files
author
Sylvestre
authored
Add support for oracle specific syntax (#326)
* oracle LIMIT as mssql * tests
1 parent 0b4f503 commit f809ad2

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

src/table.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ export function makeQueryTemplate(operations, source) {
317317
appendSql(i ? `, ` : `\nORDER BY `, args);
318318
appendOrderBy(sort[i], args, escaper);
319319
}
320-
if (source.dialect === "mssql") {
320+
if (source.dialect === "mssql" || source.dialect === "oracle") {
321321
if (slice.to !== null || slice.from !== null) {
322322
if (!sort.length) {
323323
if (!select.columns)

test/table-test.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,57 @@ describe("makeQueryTemplate", () => {
361361
assert.deepStrictEqual(parts.join("?"), "SELECT * FROM table1\nORDER BY col2 DESC\nOFFSET 10 ROWS\nFETCH NEXT 90 ROWS ONLY");
362362
assert.deepStrictEqual(params, []);
363363
});
364+
365+
it("makeQueryTemplate throw if no columns are explicitly specified for oracle dialect", () => {
366+
const source = {name: "db", dialect: "oracle"};
367+
const operations = {
368+
...baseOperations,
369+
select: {
370+
columns: null
371+
},
372+
sort: [],
373+
slice: {from: 10, to: 100}
374+
};
375+
376+
assert.throws(() => {
377+
makeQueryTemplate(operations, source);
378+
}, Error);
379+
});
380+
381+
it("makeQueryTemplate select, sort, slice, filter indexed with oracle syntax", () => {
382+
const source = {name: "db", dialect: "oracle"};
383+
const operations = {
384+
...baseOperations,
385+
select: {
386+
columns: ["col1", "col2", "col3"]
387+
},
388+
sort: [{column: "col2", direction: "desc"}],
389+
slice: {from: 10, to: 100},
390+
filter: [
391+
{
392+
type: "gte",
393+
operands: [
394+
{type: "column", value: "col1"},
395+
{type: "resolved", value: "val1"}
396+
]
397+
},
398+
{
399+
type: "eq",
400+
operands: [
401+
{type: "column", value: "col2"},
402+
{type: "resolved", value: "val2"}
403+
]
404+
}
405+
]
406+
};
407+
408+
const [parts, ...params] = makeQueryTemplate(operations, source);
409+
assert.deepStrictEqual(
410+
parts.join("?"),
411+
"SELECT col1, col2, col3 FROM table1\nWHERE col1 >= ?\nAND col2 = ?\nORDER BY col2 DESC\nOFFSET 10 ROWS\nFETCH NEXT 90 ROWS ONLY"
412+
);
413+
assert.deepStrictEqual(params, ["val1", "val2"]);
414+
});
364415
});
365416

366417
describe("__table", () => {

0 commit comments

Comments
 (0)