Skip to content

Commit

Permalink
add test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
igalklebanov committed Dec 29, 2023
1 parent ee1386c commit f8a412b
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions test/node/src/select.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1052,5 +1052,80 @@ for (const dialect of DIALECTS) {
expect(result[0]).to.eql({ person_first_name: 'Arnold' })
}
})

if (dialect === 'postgres' || dialect === 'mssql') {
it('should create a select query with order by, offset and fetch', async () => {
const query = ctx.db
.selectFrom('person')
.select('first_name')
.orderBy('first_name')
.offset(1)
.fetch(2)

testSql(query, dialect, {
postgres: {
sql: 'select "first_name" from "person" order by "first_name" offset $1 fetch next $2 rows only',
parameters: [1, 2],
},
mysql: NOT_SUPPORTED,
mssql: {
sql: 'select "first_name" from "person" order by "first_name" offset @1 rows fetch next @2 rows only',
parameters: [1, 2],
},
sqlite: NOT_SUPPORTED,
})

const result = await query.execute()
expect(result).to.have.length(2)
})

it('should create a select query with order by, offset and fetch only', async () => {
const query = ctx.db
.selectFrom('person')
.select('first_name')
.orderBy('first_name')
.offset(1)
.fetch(2, 'only')

testSql(query, dialect, {
postgres: {
sql: 'select "first_name" from "person" order by "first_name" offset $1 fetch next $2 rows only',
parameters: [1, 2],
},
mysql: NOT_SUPPORTED,
mssql: {
sql: 'select "first_name" from "person" order by "first_name" offset @1 rows fetch next @2 rows only',
parameters: [1, 2],
},
sqlite: NOT_SUPPORTED,
})

const result = await query.execute()
expect(result).to.have.length(2)
})
}

if (dialect === 'postgres') {
it('should create a select query with order by, offset and fetch with ties', async () => {
const query = ctx.db
.selectFrom('person')
.select('first_name')
.orderBy('first_name')
.offset(1)
.fetch(2, 'with ties')

testSql(query, dialect, {
postgres: {
sql: 'select "first_name" from "person" order by "first_name" offset $1 fetch next $2 rows with ties',
parameters: [1, 2],
},
mysql: NOT_SUPPORTED,
mssql: NOT_SUPPORTED,
sqlite: NOT_SUPPORTED,
})

await query.execute()
})
}
})
}

0 comments on commit f8a412b

Please sign in to comment.