Closed Wizzel1 closed 10 months ago
If you're not inserting any values, you need to add the default values
specifier by calling defaultValues()
.
You also should never make anything optional in your database interface. Please see the getting started documentation.
export type EpisodeTable = {
id: Generated<number>;
};
type Database = {
episodes: EpisodeTable;
};
export type Episode = Selectable<EpisodeTable>
export type NewEpisode = Insertable<EpisodeTable>
export type EpisodeUpdate = Updateable<EpisodeTable>
@koskimas Thanks that worked. However I have another problem where I could not find the correct documentation.
I have added a
type VideoTable = {
id: Generated<number>;
in_episodes: number[],
}
export type Video = Selectable<VideoTable>;
export type NewVideo = Insertable<VideoTable>;
export type VideoUpdate = Updatable<VideoTable>;
and I am trying to query it like this:
const videosOfEpisodeOne = await db
.selectFrom('videos')
.where('in_episodes', '@>', [1])
.selectAll()
.execute();
console.log(videosOfEpisodeOne.length);
but that returns an error:
error: malformed array literal: "1"
...
length: 181,
severity: 'ERROR',
code: '22P02',
detail: 'Array value must start with "{" or dimension information.',
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: "unnamed portal parameter $1 = '...'",
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
do I have to change the columntype of my video table here?
I am using vercels postgres database and I am trying to insert a row into it. My goal is to return the id when the row has been created.
I also tried
but that results in another error: