tantan-typeorm-gs 1.0.0
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/LICENSE +21 -0
- package/README.md +31 -0
- package/bun.lock +300 -0
- package/docs/authentication.md +118 -0
- package/docs/configuration.md +680 -0
- package/docs/contributing.md +177 -0
- package/docs/crud.md +351 -0
- package/docs/custom-client.md +165 -0
- package/docs/development.md +243 -0
- package/docs/entities.md +502 -0
- package/docs/find-options.md +296 -0
- package/docs/google-cloud.md +101 -0
- package/docs/installation.md +51 -0
- package/docs/integration-testing.md +178 -0
- package/docs/limitations.md +223 -0
- package/docs/pagination.md +384 -0
- package/docs/performance.md +171 -0
- package/docs/security.md +153 -0
- package/docs/sorting.md +0 -0
- package/docs/supported-features.md +310 -0
- package/docs/synchronization.md +203 -0
- package/package.json +43 -0
- package/src/client/index.ts +589 -0
- package/src/core/data-source.ts +47 -0
- package/src/core/driver.ts +290 -0
- package/src/core/error.ts +144 -0
- package/src/core/memory.ts +152 -0
- package/src/core/query/interpreter.ts +949 -0
- package/src/core/query/runner.ts +1297 -0
- package/src/core/query/types.ts +155 -0
- package/src/core/schema-builder.ts +64 -0
- package/src/core/types.ts +113 -0
- package/src/core/utils.ts +13 -0
- package/src/index.ts +3 -0
- package/tantan-typeorm-gs.code-workspace +8 -0
- package/test/base/0001-data-source.test.ts +252 -0
- package/test/base/0002-operator.test.ts +616 -0
- package/test/base/0003-select.test.ts +281 -0
- package/test/base/0004-aggregate.test.ts +213 -0
- package/test/base/0005-transcation.test.ts +1566 -0
- package/test/base/0006-relation.test.ts +1611 -0
- package/test/base/0007-logging.test.ts +182 -0
- package/test/base/0008-soft-delete.test.ts +649 -0
- package/test/google-sheets/0001-client.test.ts +1705 -0
- package/test/google-sheets/0002-worksheet-management.test.ts +408 -0
- package/test/google-sheets/0003-data-source.test.ts +1935 -0
- package/test/google-sheets/0004-transactions.test.ts +952 -0
- package/test/google-sheets/0005-operator.test.ts +1124 -0
- package/test/google-sheets/0006-object-criteria.test.ts +283 -0
- package/test/google-sheets/0007-performance.test.ts +532 -0
- package/test/public-api.test.ts +34 -0
- package/tsconfig.build.json +21 -0
- package/tsconfig.json +34 -0
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
## Synchronization
|
|
2
|
+
|
|
3
|
+
Synchronization allows the data source to synchronize entity metadata with the corresponding Google Sheets worksheets.
|
|
4
|
+
|
|
5
|
+
It is controlled through the `synchronize` data source option.
|
|
6
|
+
|
|
7
|
+
### Enable Synchronization
|
|
8
|
+
|
|
9
|
+
Set `synchronize` to `true` when creating the data source:
|
|
10
|
+
|
|
11
|
+
```ts id="5n7q2m"
|
|
12
|
+
const dataSource = createGoogleSheetsDataSource({
|
|
13
|
+
type: "google-sheets",
|
|
14
|
+
|
|
15
|
+
spreadsheetId: process.env.GOOGLE_SHEETS_SPREADSHEET_ID!,
|
|
16
|
+
|
|
17
|
+
credentials: {
|
|
18
|
+
clientEmail: process.env.GOOGLE_SHEETS_CLIENT_EMAIL!,
|
|
19
|
+
|
|
20
|
+
privateKey: process.env.GOOGLE_SHEETS_PRIVATE_KEY!
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
entities: [User],
|
|
24
|
+
|
|
25
|
+
synchronize: true
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
await dataSource.initialize();
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Synchronization is performed as part of the data source initialization process.
|
|
32
|
+
|
|
33
|
+
### Entity and Worksheet
|
|
34
|
+
|
|
35
|
+
For an entity:
|
|
36
|
+
|
|
37
|
+
```ts id="8c4p1v"
|
|
38
|
+
@Entity("users")
|
|
39
|
+
class User {
|
|
40
|
+
@PrimaryGeneratedColumn()
|
|
41
|
+
id!: number;
|
|
42
|
+
|
|
43
|
+
@Column()
|
|
44
|
+
name!: string;
|
|
45
|
+
|
|
46
|
+
@Column()
|
|
47
|
+
email!: string;
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
the driver uses the entity metadata to determine the worksheet and its columns.
|
|
52
|
+
|
|
53
|
+
The worksheet corresponds to:
|
|
54
|
+
|
|
55
|
+
```text id="3h8x5k"
|
|
56
|
+
users
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
and the entity columns determine the expected worksheet structure.
|
|
60
|
+
|
|
61
|
+
### When to Use Synchronization
|
|
62
|
+
|
|
63
|
+
Synchronization is useful when the application owns the structure of the target spreadsheet and wants the worksheet structure to follow the entity metadata.
|
|
64
|
+
|
|
65
|
+
A typical development configuration is:
|
|
66
|
+
|
|
67
|
+
```ts id="1q6m9s"
|
|
68
|
+
const dataSource = createGoogleSheetsDataSource({
|
|
69
|
+
// ...
|
|
70
|
+
|
|
71
|
+
entities: [User],
|
|
72
|
+
|
|
73
|
+
synchronize: true
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
The application then initializes the data source:
|
|
78
|
+
|
|
79
|
+
```ts id="6v2k8p"
|
|
80
|
+
await dataSource.initialize();
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Synchronization vs CRUD
|
|
84
|
+
|
|
85
|
+
Synchronization is different from inserting or updating data.
|
|
86
|
+
|
|
87
|
+
CRUD operations modify records:
|
|
88
|
+
|
|
89
|
+
```text
|
|
90
|
+
insert
|
|
91
|
+
↓
|
|
92
|
+
rows
|
|
93
|
+
|
|
94
|
+
update
|
|
95
|
+
↓
|
|
96
|
+
rows
|
|
97
|
+
|
|
98
|
+
delete
|
|
99
|
+
↓
|
|
100
|
+
rows
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Synchronization deals with the schema represented by entity metadata:
|
|
104
|
+
|
|
105
|
+
```text
|
|
106
|
+
Entity metadata
|
|
107
|
+
↓
|
|
108
|
+
Synchronization
|
|
109
|
+
↓
|
|
110
|
+
Worksheet structure
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Therefore, `synchronize` should not be enabled simply because the application needs to perform CRUD operations.
|
|
114
|
+
|
|
115
|
+
### `dropSchema`
|
|
116
|
+
|
|
117
|
+
The data source also exposes the `dropSchema` option:
|
|
118
|
+
|
|
119
|
+
```ts id="4m7r2x"
|
|
120
|
+
const dataSource = createGoogleSheetsDataSource({
|
|
121
|
+
// ...
|
|
122
|
+
|
|
123
|
+
entities: [User],
|
|
124
|
+
|
|
125
|
+
synchronize: true,
|
|
126
|
+
dropSchema: true
|
|
127
|
+
});
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
This option should be used with caution because schema-dropping operations can remove existing worksheet structures or data depending on the synchronization operation.
|
|
131
|
+
|
|
132
|
+
It is generally more appropriate for controlled development or testing environments than for production data.
|
|
133
|
+
|
|
134
|
+
### Initialization Lifecycle
|
|
135
|
+
|
|
136
|
+
Synchronization is associated with data source initialization:
|
|
137
|
+
|
|
138
|
+
```ts id="0q8c4n"
|
|
139
|
+
await dataSource.initialize();
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Once initialization has completed, repositories can be obtained normally:
|
|
143
|
+
|
|
144
|
+
```ts id="2m5v7x"
|
|
145
|
+
const repository = dataSource.getRepository(User);
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
The data source should be destroyed when the application no longer needs the connection:
|
|
149
|
+
|
|
150
|
+
```ts id="9p4k1w"
|
|
151
|
+
await dataSource.destroy();
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Production Considerations
|
|
155
|
+
|
|
156
|
+
Synchronization should be used carefully when the spreadsheet contains production data.
|
|
157
|
+
|
|
158
|
+
Before enabling synchronization in production, consider:
|
|
159
|
+
|
|
160
|
+
- whether the application should be allowed to modify worksheet structure
|
|
161
|
+
- whether existing spreadsheet data must be preserved
|
|
162
|
+
- whether schema changes should be controlled explicitly
|
|
163
|
+
- whether the spreadsheet is shared with other applications or users
|
|
164
|
+
|
|
165
|
+
Google Sheets is not a relational database, so schema synchronization should be treated as worksheet-structure management rather than a database migration system.
|
|
166
|
+
|
|
167
|
+
### Recommended Development Pattern
|
|
168
|
+
|
|
169
|
+
For development or controlled environments:
|
|
170
|
+
|
|
171
|
+
```ts id="7x3n5q"
|
|
172
|
+
const dataSource = createGoogleSheetsDataSource({
|
|
173
|
+
type: "google-sheets",
|
|
174
|
+
|
|
175
|
+
spreadsheetId: process.env.GOOGLE_SHEETS_SPREADSHEET_ID!,
|
|
176
|
+
|
|
177
|
+
credentials: {
|
|
178
|
+
clientEmail: process.env.GOOGLE_SHEETS_CLIENT_EMAIL!,
|
|
179
|
+
|
|
180
|
+
privateKey: process.env.GOOGLE_SHEETS_PRIVATE_KEY!
|
|
181
|
+
},
|
|
182
|
+
|
|
183
|
+
entities: [User],
|
|
184
|
+
|
|
185
|
+
synchronize: true
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
await dataSource.initialize();
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
For production, synchronization should be enabled only when the application intentionally owns the worksheet structure.
|
|
192
|
+
|
|
193
|
+
### Summary
|
|
194
|
+
|
|
195
|
+
The main options related to synchronization are:
|
|
196
|
+
|
|
197
|
+
| Option | Purpose |
|
|
198
|
+
| ------------- | ------------------------------------------------------------- |
|
|
199
|
+
| `synchronize` | Synchronize entity metadata with worksheet structure |
|
|
200
|
+
| `dropSchema` | Drop schema/worksheet structures as part of schema management |
|
|
201
|
+
| `entities` | Define the entity metadata used during synchronization |
|
|
202
|
+
|
|
203
|
+
Synchronization happens during data source initialization and is separate from normal CRUD operations.
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tantan-typeorm-gs",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A TypeORM-compatible driver for using Google Sheets as a data source.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"typeorm",
|
|
7
|
+
"google-sheets",
|
|
8
|
+
"google-sheets-api",
|
|
9
|
+
"typeorm-driver",
|
|
10
|
+
"typeorm-driver-google-sheets",
|
|
11
|
+
"database",
|
|
12
|
+
"orm",
|
|
13
|
+
"typescript",
|
|
14
|
+
"bun"
|
|
15
|
+
],
|
|
16
|
+
"module": "src/index.ts",
|
|
17
|
+
"type": "module",
|
|
18
|
+
"main": "./dist/index.js",
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"import": "./dist/index.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"typecheck": "tsc --noEmit",
|
|
29
|
+
"build": "tsc -p tsconfig.build.json",
|
|
30
|
+
"test": "bun test",
|
|
31
|
+
"test:run": "bun test"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"googleapis": "^178.0.0",
|
|
35
|
+
"typeorm": "^1.1.1"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/bun": "latest"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"typescript": "^7"
|
|
42
|
+
}
|
|
43
|
+
}
|