-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from farreldarian/pgd-37-foreign-key-is-not-co…
…rrectly-generated-for-implicit-mn fix: hardcoding M:N implicit relation pk
- Loading branch information
Showing
4 changed files
with
112 additions
and
5 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
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 |
---|---|---|
@@ -1,4 +1,20 @@ | ||
import type { BinaryOperator, Column, GetColumnData } from 'drizzle-orm' | ||
|
||
export function throwIfnull<T>(data: T | undefined) { | ||
if (data == null) throw new Error('data is null') | ||
return data | ||
} | ||
|
||
export function shouldReturnOne<T>(results: Array<T>): T { | ||
const result = results.at(0) | ||
if (result == null) | ||
throw new Error(`Expected one result from ${results}, got none`) | ||
return result | ||
} | ||
|
||
export function matchesId<TColumn extends Column>( | ||
id: GetColumnData<TColumn, 'raw'> | ||
) { | ||
return (table: { id: TColumn }, { eq }: { eq: BinaryOperator }) => | ||
eq(table.id, id) | ||
} |