orchid-orm 1.5.16 → 1.5.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orchid-orm",
3
- "version": "1.5.16",
3
+ "version": "1.5.18",
4
4
  "description": "Postgres ORM",
5
5
  "homepage": "https://orchid-orm.netlify.app/guide/orm-setup-and-overview.html",
6
6
  "repository": {
@@ -40,7 +40,7 @@
40
40
  "author": "Roman Kushyn",
41
41
  "license": "ISC",
42
42
  "dependencies": {
43
- "pqb": "0.9.10",
43
+ "pqb": "0.9.12",
44
44
  "prompts": "^2.4.2"
45
45
  },
46
46
  "devDependencies": {
@@ -52,10 +52,10 @@
52
52
  "@types/prompts": "^2.4.2",
53
53
  "dotenv": "^16.0.1",
54
54
  "jest": "^28.1.2",
55
- "orchid-orm-schema-to-zod": "0.2.16",
55
+ "orchid-orm-schema-to-zod": "0.2.18",
56
56
  "pg": "^8.7.3",
57
57
  "pg-transactional-tests": "^1.0.7",
58
- "rake-db": "2.3.15",
58
+ "rake-db": "2.3.17",
59
59
  "rimraf": "^3.0.2",
60
60
  "rollup": "^2.79.0",
61
61
  "rollup-plugin-dts": "^4.2.2",
@@ -441,7 +441,7 @@ export class PostTable extends BaseTable {
441
441
  table = 'post';
442
442
  columns = this.setColumns((t) => ({
443
443
  id: t.serial().primaryKey(),
444
- title: t.text(3, 100),
444
+ title: t.text(3, 100).unique(),
445
445
  text: t.text(20, 10000),
446
446
  ...t.timestamps(),
447
447
  }));
@@ -474,7 +474,7 @@ export class PostTable extends BaseTable {
474
474
  table = 'post';
475
475
  columns = this.setColumns((t) => ({
476
476
  id: t.serial().primaryKey(),
477
- title: t.text(3, 100),
477
+ title: t.text(3, 100).unique(),
478
478
  text: t.text(20, 10000),
479
479
  ...t.timestamps(),
480
480
  }));
@@ -735,7 +735,7 @@ rakeDb(config.allDatabases, {
735
735
  change(async (db) => {
736
736
  await db.createTable('post', (t) => ({
737
737
  id: t.serial().primaryKey(),
738
- title: t.text(),
738
+ title: t.text().unique(),
739
739
  text: t.text(),
740
740
  ...t.timestamps(),
741
741
  }));
package/src/bin/init.ts CHANGED
@@ -256,7 +256,7 @@ export class PostTable extends BaseTable {
256
256
  table = 'post';
257
257
  columns = this.setColumns((t) => ({
258
258
  id: t.serial().primaryKey(),
259
- title: t.text(3, 100),
259
+ title: t.text(3, 100).unique(),
260
260
  text: t.text(20, 10000),
261
261
  ...t.timestamps(),
262
262
  }));
@@ -430,7 +430,7 @@ const createMigrations = async (config: InitConfig) => {
430
430
  change(async (db) => {
431
431
  await db.createTable('post', (t) => ({
432
432
  id: t.serial().primaryKey(),
433
- title: t.text(),
433
+ title: t.text().unique(),
434
434
  text: t.text(),
435
435
  ...t.timestamps(),
436
436
  }));
@@ -489,7 +489,8 @@ export const seed = async () => {
489
489
  };
490
490
 
491
491
  const greet = () => {
492
- console.log(`Thank you for trying Orchid ORM!
492
+ console.log(`
493
+ Thank you for trying Orchid ORM!
493
494
 
494
495
  To finish setup, install dependencies:
495
496
 
@@ -502,5 +503,6 @@ then create the database:
502
503
 
503
504
  And run the migrations:
504
505
 
505
- > npm run db migrate`);
506
+ > npm run db migrate
507
+ `);
506
508
  };
@@ -109,10 +109,10 @@ export const db = orchidORM({}, {
109
109
  it('should handle object list without ending coma', async () => {
110
110
  asMock(fs.readFile).mockResolvedValue(`
111
111
  import { orchidORM } from 'orchid-orm';
112
- import { Some } from './tables/some';
112
+ import { MyTable } from './tables/my.table';
113
113
 
114
114
  export const db = orchidORM({}, {
115
- some: Some
115
+ my: MyTable,
116
116
  });
117
117
  `);
118
118
 
@@ -120,15 +120,30 @@ export const db = orchidORM({}, {
120
120
 
121
121
  testWritten(`
122
122
  import { orchidORM } from 'orchid-orm';
123
- import { Some } from './tables/some';
123
+ import { MyTable } from './tables/my.table';
124
124
  import { SomeTable } from './tables/some.table';
125
125
 
126
126
  export const db = orchidORM({}, {
127
- some: Some,
127
+ my: MyTable,
128
128
  some: SomeTable,
129
129
  });
130
130
  `);
131
131
  });
132
+
133
+ it('should not add table if it is already added', async () => {
134
+ asMock(fs.readFile).mockResolvedValue(`
135
+ import { orchidORM } from 'orchid-orm';
136
+ import { SomeTable } from './tables/some.table';
137
+
138
+ export const db = orchidORM({}, {
139
+ some: SomeTable
140
+ });
141
+ `);
142
+
143
+ await updateMainFile(mainFilePath, tablePath, ast.addTable, options);
144
+
145
+ expect(fs.writeFile).not.toBeCalled();
146
+ });
132
147
  });
133
148
 
134
149
  describe('drop table', () => {
@@ -122,6 +122,12 @@ const createTable = (
122
122
  const changes = new FileChanges(content);
123
123
 
124
124
  const importPath = getImportPath(filePath, tablePath(ast.name));
125
+
126
+ const existing = Array.from(
127
+ ts.import.iterateWithSource(statements, importPath),
128
+ );
129
+ if (existing.length) return;
130
+
125
131
  const importPos = ts.import.getEndPos(statements);
126
132
  changes.add(
127
133
  importPos,