Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wide-dodos-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/db': minor
---

Upgraded drizzle-orm to latest v0.42.0
2 changes: 1 addition & 1 deletion packages/db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"@libsql/client": "^0.15.2",
"async-listen": "^3.1.0",
"deep-diff": "^1.0.2",
"drizzle-orm": "^0.31.2",
"drizzle-orm": "^0.42.0",
"github-slugger": "^2.0.0",
"kleur": "^4.1.5",
"nanoid": "^5.1.5",
Expand Down
4 changes: 2 additions & 2 deletions packages/db/src/runtime/index.ts
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change was made due to a change in Drizzle, indexes are now expected to be an array instead of an object.

Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ export function asDrizzleTable(name: string, table: DBTable) {
columns[columnName] = columnMapper(columnName, column);
}
const drizzleTable = sqliteTable(name, columns, (ormTable) => {
const indexes: Record<string, IndexBuilder> = {};
const indexes: Array<IndexBuilder> = [];
for (const [indexName, indexProps] of Object.entries(table.indexes ?? {})) {
const onColNames = Array.isArray(indexProps.on) ? indexProps.on : [indexProps.on];
const onCols = onColNames.map((colName) => ormTable[colName]);
if (!atLeastOne(onCols)) continue;

indexes[indexName] = index(indexName).on(...onCols);
indexes.push(index(indexName).on(...onCols));
}
return indexes;
});
Expand Down
15 changes: 15 additions & 0 deletions packages/db/src/runtime/types.ts
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added new properties from Drizzle column

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ type AstroText<T extends GeneratedConfig<'string'>> = SQLiteColumn<
driverParam: string;
enumValues: never;
baseColumn: never;
isPrimaryKey: boolean;
isAutoincrement: boolean;
hasRuntimeDefault: boolean;
}
>;

Expand All @@ -26,6 +29,9 @@ type AstroDate<T extends GeneratedConfig<'custom'>> = SQLiteColumn<
driverParam: string;
enumValues: never;
baseColumn: never;
isPrimaryKey: boolean;
isAutoincrement: boolean;
hasRuntimeDefault: boolean;
}
>;

Expand All @@ -37,6 +43,9 @@ type AstroBoolean<T extends GeneratedConfig<'boolean'>> = SQLiteColumn<
driverParam: number;
enumValues: never;
baseColumn: never;
isPrimaryKey: boolean;
isAutoincrement: boolean;
hasRuntimeDefault: boolean;
}
>;

Expand All @@ -48,6 +57,9 @@ type AstroNumber<T extends GeneratedConfig<'number'>> = SQLiteColumn<
driverParam: number;
enumValues: never;
baseColumn: never;
isPrimaryKey: boolean;
isAutoincrement: boolean;
hasRuntimeDefault: boolean;
}
>;

Expand All @@ -59,6 +71,9 @@ type AstroJson<T extends GeneratedConfig<'custom'>> = SQLiteColumn<
driverParam: string;
enumValues: never;
baseColumn: never;
isPrimaryKey: boolean;
isAutoincrement: boolean;
hasRuntimeDefault: boolean;
}
>;

Expand Down
2 changes: 1 addition & 1 deletion packages/db/src/utils.ts
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix for incompatible types

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function asDrizzleTable<
TableName extends string = string,
TColumns extends ColumnsConfig = ColumnsConfig,
>(name: TableName, tableConfig: TableConfig<TColumns>) {
return internal_asDrizzleTable(name, tableSchema.parse(tableConfig)) as Table<
return internal_asDrizzleTable(name, tableSchema.parse(tableConfig)) as unknown as Table<
TableName,
TColumns
>;
Expand Down
37 changes: 18 additions & 19 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.