Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #9

Merged
merged 41 commits into from
Dec 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
a486a20
Move types pg types to prod dependencies
AndriiSherman Sep 11, 2021
660db57
Change version to 0.9.0
AndriiSherman Sep 11, 2021
3f2e457
Add type for every exception
AndriiSherman Sep 11, 2021
eba7b70
Update setters for update statement together with enum types hadnling…
AndriiSherman Sep 23, 2021
7f2c6bf
0.9.1
AndriiSherman Sep 25, 2021
a330bb6
Update README docs (#2)
AndriiSherman Nov 20, 2021
e503f5f
Merge branch 'develop' of https://github.com/lambda-direct/drizzle-or…
AndriiSherman Nov 20, 2021
b643d32
Feature/last updates (#3)
AndriiSherman Nov 30, 2021
d382c37
Merge branch 'develop' of https://github.com/lambda-direct/drizzle-or…
AndriiSherman Nov 30, 2021
ef1f164
0.9.2
AndriiSherman Nov 30, 2021
ef5c3c9
Add serial to serializer
AndriiSherman Dec 4, 2021
d985baf
0.9.3
AndriiSherman Dec 4, 2021
71679dd
Add onConstraint for serializer
AndriiSherman Dec 4, 2021
e253465
0.9.4
AndriiSherman Dec 4, 2021
635e709
Move ON DELETE and ON UPDATE to references
AndriiSherman Dec 4, 2021
189b3b5
0.9.5
AndriiSherman Dec 4, 2021
0857c7b
Add foreignKeyName to serializer
AndriiSherman Dec 4, 2021
3cd5db9
0.9.6
AndriiSherman Dec 4, 2021
fc8ea14
Improvements (#4)
AndriiSherman Dec 6, 2021
fc093a4
Merge branch 'develop' of https://github.com/lambda-direct/drizzle-or…
AndriiSherman Dec 6, 2021
ceb6d45
0.9.7
AndriiSherman Dec 7, 2021
efc81d1
onContrsaint as optional
AndriiSherman Dec 7, 2021
a015511
0.9.8
AndriiSherman Dec 7, 2021
388cd46
Fix serializer key
AndriiSherman Dec 13, 2021
4c99083
0.9.9
AndriiSherman Dec 13, 2021
3c8541c
0.9.10
AndriiSherman Dec 13, 2021
1e7a09f
Fix Nan exception on mapping
AndriiSherman Dec 16, 2021
a939b9e
Add smallInt type
AndriiSherman Dec 16, 2021
48c6590
0.9.11
AndriiSherman Dec 16, 2021
114e322
Export ExtractModel type
AndriiSherman Dec 17, 2021
c32d6a5
0.9.12
AndriiSherman Dec 17, 2021
5a2d566
Feature/knex (#6)
AndriiSherman Dec 23, 2021
b59d8c1
Merge branch 'develop' of https://github.com/lambda-direct/drizzle-or…
AndriiSherman Dec 23, 2021
ca232ac
0.9.13
AndriiSherman Dec 23, 2021
1da6b77
0.9.14
AndriiSherman Dec 23, 2021
b075651
Export ISession
AndriiSherman Dec 23, 2021
13d3c58
0.9.15
AndriiSherman Dec 23, 2021
daefc39
Release/0.9.16 (#7)
AndriiSherman Dec 27, 2021
7b53d13
Merge branch 'develop' of https://github.com/lambda-direct/drizzle-or…
AndriiSherman Dec 27, 2021
2ede3b5
Add serializer to introspect database to json snapshot (#8)
AndriiSherman Dec 27, 2021
efaa70a
Merge branch 'main' of https://github.com/lambda-direct/drizzle-orm i…
AndriiSherman Dec 27, 2021
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
78 changes: 78 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Changelog

### 0.9.17 (December 27, 2021)
### Fixes and Functionality:
- Add serializer `fromDb()` method to introspect selected database to drizzle-kit json shanpsot format

---
### 0.9.16 (December 27, 2021)
### Breaking changes:
- Delete `autoincrement` type on columns. Right now you should use `serial` type

#### Previous serial column defining:
```typescript
public id = this.int('id').autoincrement();
```
#### Current serial column defining:
```typescript
public id = this.serial('id');
```

- Move `notNull` from column type metadata to builder chain
#### Previous notNull defining:
```typescript
public phone = this.varchar('phone', { notNull: true });
```
#### Current notNull defining:
```typescript
public phone = this.varchar('phone').notNull();
```

- Divide `BigInt` into 2 types -> `BigInt53` and `BigInt64`
- Divide `BigSerial` into 2 types -> `BigSerial53` and `BigSerial64`

Due to have max value for big integers in postgres as 2^64 and javascript max value for integers is 2^53

If you sure, that value in this column won't be more than 2^53 you could use:
```typescript
public bigIntField = this.bigint('test1', 'max_bytes_53');
```
that will be of type `number` in typescript

If value in this column could be more than 2^53 you could use:
```typescript
public bigIntField = this.bigint('test1', 'max_bytes_64');
```
that will be of type `bigint` in typescript
---

### Fixes and Functionality:
- Add `SET NULL` and `SET DEFAULT` for `ON DELETE` and `ON UPDATE` constraints

#### Example of usage
```typescript
public userId = this.int('user_id').foreignKey(UsersTable, (table) => table.id, { onUpdate: 'SET NULL' });

public userId = this.int('user_id').foreignKey(UsersTable, (table) => table.id, { onDelete: 'SET DEFAULT' });
```
- Add default value for timestamp
```typescript
public createdAt = this.timestamp('created_at').defaultValue(Defaults.CURRENT_TIMESTAMP);
```
- Add `timestamp with timezone` type
```typescript
public createdAt = this.timestamptz('created_at');
```
- Add migrator function to use `drizzle-kit` generated migrations
##### Provide drizzle-kit config path
```typescript
await drizzle.migrator(db).migrate('src/drizzle.config.yaml');
```
##### Provide object with path to folder with migrations
```typescript
await drizzle.migrator(db).migrate({ migrationFolder: 'drizzle' });
```
---

### Documentation:
- Change README documentation for all changes in current release
38 changes: 26 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,20 @@ const db = await new DbConnector()
export const rolesEnum = createEnum({ alias: 'test-enum', values: ['user', 'guest', 'admin'] });

export default class UsersTable extends AbstractTable<UsersTable> {
public id = this.int('id').autoIncrement().primaryKey();
public id = this.serial('id').primaryKey();
public fullName = this.text('full_name');

public phone = this.varchar('phone', { size: 256 });
public media = this.jsonb<string[]>('media');
public decimalField = this.decimal('test', { notNull: true, precision: 100, scale: 2 });
public bigIntField = this.bigint('test1');
public role = this.type(rolesEnum, 'name_in_table', { notNull: true });
public decimalField = this.decimal('test', { precision: 100, scale: 2 }).notNull();
public bigIntField = this.bigint('test1', 'max_bytes_53');
public role = this.type(rolesEnum, 'name_in_table').notNull();

public createdAt = this.timestamp('created_at', { notNull: true });
public updatedAt = this.timestamp('updated_at');
public createdAt = this.timestamp('created_at').notNull();

public createdAtWithTimezone = this.timestamptz('created_at_time_zone');

public updatedAt = this.timestamp('updated_at').defaultValue(Defaults.CURRENT_TIMESTAMP);
public isArchived = this.bool('is_archived').defaultValue(false);

public phoneFullNameIndex = this.index([this.phone, this.fullName]);
Expand All @@ -90,12 +93,12 @@ interface CityMeta {
}

export default class CitiesTable extends AbstractTable<CitiesTable> {
public id = this.int('id').autoIncrement().primaryKey();
public id = this.serial('id').primaryKey();

public foundationDate = this.timestamp('name', { notNull: true });
public foundationDate = this.timestamp('name').notNull();
public location = this.varchar('page', { size: 256 });

public userId = this.int('user_id').foreignKey(UsersTable, (table) => table.id, OnDelete.CASCADE);
public userId = this.int('user_id').foreignKey(UsersTable, (table) => table.id, { onUpdate: 'CASCADE' });

public metadata = this.jsonb<CityMeta>('metadata');

Expand All @@ -108,7 +111,7 @@ export default class CitiesTable extends AbstractTable<CitiesTable> {
---
```typescript
export default class UserGroupsTable extends AbstractTable<UserGroupsTable> {
public id = this.int('id').autoIncrement().primaryKey();
public id = this.serial('id').primaryKey();

public name = this.varchar('name');
public description = this.varchar('description');
Expand All @@ -123,8 +126,8 @@ export default class UserGroupsTable extends AbstractTable<UserGroupsTable> {
#### Many to many connection between Users and User Groups
```typescript
export default class UsersToUserGroupsTable extends AbstractTable<UsersToUserGroupsTable> {
public groupId = this.int('city_id').foreignKey(UserGroupsTable, (table) => table.id, OnDelete.CASCADE);
public userId = this.int('user_id').foreignKey(UsersTable, (table) => table.id, OnDelete.CASCADE);
public groupId = this.int('city_id').foreignKey(UserGroupsTable, (table) => table.id, { onDelete: 'CASCADE' });
public userId = this.int('user_id').foreignKey(UsersTable, (table) => table.id, { onDelete: 'CASCADE' });

public manyToManyIndex = this.index([this.groupId, this.userId]);

Expand Down Expand Up @@ -382,4 +385,15 @@ const citiesWithUserObject = userWithCities.map((city, user) => ({ ...city, user
...userGroupWithUsers.one,
users: userGroupWithUsers.many,
};
```

## Migrations
#### To run migrations generated by drizzle-kit you could use `Migtator` class
##### Provide drizzle-kit config path
```typescript
await drizzle.migrator(db).migrate('src/drizzle.config.yaml');
```
##### Provide object with path to folder with migrations
```typescript
await drizzle.migrator(db).migrate({ migrationFolder: 'drizzle' });
```
Loading