52 lines
2.0 KiB
Markdown
52 lines
2.0 KiB
Markdown
## Features
|
||
|
||
### Duplicate imports removal
|
||
|
||
When importing from `drizzle-orm` using custom loaders, you may encounter issues such as: `SyntaxError: The requested module 'drizzle-orm' does not provide an export named 'eq'`
|
||
|
||
This issue arose because there were duplicated exports in `drizzle-orm`. To address this, we added a set of tests that checks every file in `drizzle-orm` to ensure all exports are valid. These tests will fail if any new duplicated exports appear.
|
||
|
||
In this release, we’ve removed all duplicated exports, so you should no longer encounter this issue.
|
||
|
||
### `pgEnum` and `mysqlEnum` now can accept both strings and TS enums
|
||
|
||
If you provide a TypeScript enum, all your types will be inferred as that enum - so you can insert and retrieve enum values directly. If you provide a string union, it will work as before.
|
||
|
||
```ts
|
||
enum Test {
|
||
a = 'a',
|
||
b = 'b',
|
||
c = 'c',
|
||
}
|
||
|
||
const tableWithTsEnums = mysqlTable('enums_test_case', {
|
||
id: serial().primaryKey(),
|
||
enum1: mysqlEnum(Test).notNull(),
|
||
enum2: mysqlEnum(Test).default(Test.a),
|
||
});
|
||
|
||
await db.insert(tableWithTsEnums).values([
|
||
{ id: 1, enum1: Test.a, enum2: Test.b, enum3: Test.c },
|
||
{ id: 2, enum1: Test.a, enum3: Test.c },
|
||
{ id: 3, enum1: Test.a },
|
||
]);
|
||
|
||
const res = await db.select().from(tableWithTsEnums);
|
||
|
||
expect(res).toEqual([
|
||
{ id: 1, enum1: 'a', enum2: 'b', enum3: 'c' },
|
||
{ id: 2, enum1: 'a', enum2: 'a', enum3: 'c' },
|
||
{ id: 3, enum1: 'a', enum2: 'a', enum3: 'b' },
|
||
]);
|
||
```
|
||
|
||
## Improvements
|
||
- Make `inArray` accept `ReadonlyArray` as a value - thanks @Zamiell
|
||
- Pass row type parameter to `@planetscale/database`'s execute - thanks @ayrton
|
||
- New `InferEnum` type - thanks @totigm
|
||
|
||
## Issues closed
|
||
|
||
- [Add first-class support for TS native enums](https://github.com/drizzle-team/drizzle-orm/issues/332)
|
||
- [[FEATURE]: support const enums](https://github.com/drizzle-team/drizzle-orm/issues/2798)
|
||
- [[BUG]: SyntaxError: The requested module 'drizzle-orm' does not provide an export named 'lte'](https://github.com/drizzle-team/drizzle-orm/issues/4079) |