-
-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(query_builder): add orderByRandom
- Loading branch information
1 parent
8c333e0
commit 008ec0e
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5439,6 +5439,49 @@ test.group('Query Builder | orderByRaw', (group) => { | |
}) | ||
}) | ||
|
||
test.group('Query Builder | orderByRandom', (group) => { | ||
group.setup(async () => { | ||
await setup() | ||
}) | ||
|
||
group.teardown(async () => { | ||
await cleanup() | ||
}) | ||
|
||
group.each.teardown(async () => { | ||
await resetTables() | ||
}) | ||
|
||
test('define order by random value', async ({ assert }) => { | ||
const connection = new Connection('primary', getConfig(), logger) | ||
connection.connect() | ||
|
||
const db = getQueryBuilder(getQueryClient(connection)) | ||
await getInsertBuilder(getQueryClient(connection)) | ||
.table('users') | ||
.multiInsert([ | ||
{ | ||
username: 'virk', | ||
email: '[email protected]', | ||
}, | ||
{ | ||
username: 'romain', | ||
email: '[email protected]', | ||
}, | ||
{ | ||
username: 'nikk', | ||
email: '[email protected]', | ||
}, | ||
]) | ||
|
||
const users = await db.from('users').orderByRandom() | ||
const users2 = await db.from('users').orderByRandom() | ||
|
||
assert.notEqual(users[0].id, users2[0].id) | ||
await connection.disconnect() | ||
}).retry(3) | ||
}) | ||
|
||
test.group('Query Builder | offset', (group) => { | ||
group.setup(async () => { | ||
await setup() | ||
|