@dbos-inc/typeorm-datasource 5.3.4-preview → 5.3.6-preview

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.
@@ -1,14 +0,0 @@
1
- import { Entity, PrimaryGeneratedColumn, Column, ManyToOne } from 'typeorm';
2
- import { User } from './User';
3
-
4
- @Entity()
5
- export class Photo {
6
- @PrimaryGeneratedColumn()
7
- id!: number;
8
-
9
- @Column()
10
- url!: string;
11
-
12
- @ManyToOne(() => User, (user) => user.photos)
13
- user!: User;
14
- }
@@ -1,14 +0,0 @@
1
- import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from 'typeorm';
2
- import { Photo } from './Photo';
3
-
4
- @Entity()
5
- export class User {
6
- @PrimaryGeneratedColumn()
7
- id!: number;
8
-
9
- @Column()
10
- name!: string;
11
-
12
- @OneToMany(() => Photo, (photo) => photo.user)
13
- photos!: Photo[];
14
- }
@@ -1,13 +0,0 @@
1
- import { Client } from 'pg';
2
-
3
- export async function ensureDB(client: Client, name: string) {
4
- const results = await client.query('SELECT 1 FROM pg_database WHERE datname = $1', [name]);
5
- if (results.rows.length === 0) {
6
- await client.query(`CREATE DATABASE ${name}`);
7
- }
8
- }
9
-
10
- export async function dropDB(client: Client, name: string, force: boolean = false) {
11
- const withForce = force ? ' WITH (FORCE)' : '';
12
- await client.query(`DROP DATABASE IF EXISTS ${name} ${withForce}`);
13
- }
@@ -1,95 +0,0 @@
1
- import 'reflect-metadata';
2
-
3
- import { User } from './demoentities/User';
4
- import { Photo } from './demoentities/Photo';
5
- import { DataSource } from 'typeorm';
6
-
7
- import { TypeOrmDataSource } from '..';
8
-
9
- import { DBOS } from '@dbos-inc/dbos-sdk';
10
- import { Client } from 'pg';
11
- import { ensurePGDatabase } from '../../../dist/src/database_utils';
12
-
13
- const config = { user: process.env.PGUSER || 'postgres', database: 'typeorm_ds_test_datasource' };
14
-
15
- export const AppDataSource = new DataSource({
16
- type: 'postgres',
17
- database: config.database,
18
- username: config.user,
19
- synchronize: true, // auto-create schema in dev
20
- logging: false,
21
- entities: ['./tests/demoentities/**/*.{ts,js}'], // glob pattern
22
- });
23
-
24
- const dataSource: TypeOrmDataSource = TypeOrmDataSource.createFromDataSource('appdb', AppDataSource);
25
-
26
- const workflow = DBOS.registerWorkflow(
27
- async () => {
28
- await dataSource.runTransaction(
29
- async () => {
30
- const user = dataSource.entityManager.create(User, { name: 'Alice' });
31
- await dataSource.entityManager.save(user);
32
-
33
- // attach a photo
34
- const photo = dataSource.entityManager.create(Photo, { url: 'https://example.com/me.jpg', user });
35
- await dataSource.entityManager.save(photo);
36
- },
37
- { name: 'insert' },
38
- );
39
-
40
- const nusers = await dataSource.runTransaction(
41
- async () => {
42
- const users = await AppDataSource.getRepository(User).find({
43
- relations: ['photos'],
44
- });
45
- return users.length;
46
- },
47
- { name: 'select' },
48
- );
49
-
50
- return nusers;
51
- },
52
- { name: 'testTypeOrm' },
53
- );
54
-
55
- // ensurePGDatabase swallows every failure, so verify the postcondition and fail with the reason.
56
- async function ensureTestDatabase(databaseUrl: string) {
57
- const notes: string[] = [];
58
- const record = (msg: string) => {
59
- notes.push(msg);
60
- };
61
- await ensurePGDatabase(databaseUrl, { info: record, warn: record });
62
- const client = new Client({ connectionString: databaseUrl });
63
- try {
64
- await client.connect();
65
- // CockroachDB connects to a nonexistent database, so hit a catalog that requires it to exist.
66
- await client.query('SELECT 1 FROM information_schema.schemata LIMIT 1');
67
- } catch (e) {
68
- const why = notes.length ? ` [${notes.join('; ')}]` : '';
69
- throw new Error(`Could not provision the test database: ${(e as Error).message}${why}`);
70
- } finally {
71
- await client.end().catch(() => {});
72
- }
73
- }
74
-
75
- describe('TypeOrmDataSourceDemo', () => {
76
- beforeEach(async () => {
77
- await ensureTestDatabase(
78
- `postgresql://${config.user}:${process.env['PGPASSWORD'] || 'dbos'}@${process.env['PGHOST'] || 'localhost'}:${process.env['PGPORT'] || '5432'}/typeorm_demo_ds`,
79
- );
80
- await TypeOrmDataSource.initializeDBOSSchema(config);
81
- await AppDataSource.initialize();
82
-
83
- DBOS.setConfig({ name: 'typeorm-demo-ds' });
84
- await DBOS.launch();
85
- });
86
-
87
- afterEach(async () => {
88
- await DBOS.shutdown();
89
- });
90
-
91
- test('insert dataSource.register function', async () => {
92
- const nusers = await workflow();
93
- expect(nusers).toBe(1);
94
- });
95
- });
package/tsconfig.json DELETED
@@ -1,9 +0,0 @@
1
- /* Visit https://aka.ms/tsconfig to read more about this file */
2
- {
3
- "extends": "../../tsconfig.shared.json",
4
- "compilerOptions": {
5
- "outDir": "./dist"
6
- },
7
- "include": ["index.ts"],
8
- "exclude": ["dist", "tests"]
9
- }