@travetto/model-mysql 6.0.0-rc.0 → 6.0.0-rc.2
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/README.md +7 -13
- package/__index__.ts +2 -2
- package/package.json +8 -8
- package/src/connection.ts +5 -5
- package/src/dialect.ts +2 -3
package/README.md
CHANGED
|
@@ -13,17 +13,17 @@ npm install @travetto/model-mysql
|
|
|
13
13
|
yarn add @travetto/model-mysql
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
This module provides a [MySQL](https://www.mysql.com/)-based implementation for the [Data Modeling Support](https://github.com/travetto/travetto/tree/main/module/model#readme "Datastore abstraction for core operations.") module. This source allows the [Data Modeling Support](https://github.com/travetto/travetto/tree/main/module/model#readme "Datastore abstraction for core operations.") module to read, write and query against [SQL](https://en.wikipedia.org/wiki/SQL) databases. In development mode, the [SQLModelService](https://github.com/travetto/travetto/tree/main/module/model-sql/src/service.ts#
|
|
16
|
+
This module provides a [MySQL](https://www.mysql.com/)-based implementation for the [Data Modeling Support](https://github.com/travetto/travetto/tree/main/module/model#readme "Datastore abstraction for core operations.") module. This source allows the [Data Modeling Support](https://github.com/travetto/travetto/tree/main/module/model#readme "Datastore abstraction for core operations.") module to read, write and query against [SQL](https://en.wikipedia.org/wiki/SQL) databases. In development mode, the [SQLModelService](https://github.com/travetto/travetto/tree/main/module/model-sql/src/service.ts#L32) will also modify the database schema in real time to minimize impact to development.
|
|
17
17
|
|
|
18
18
|
The schema generated will not generally map to existing tables as it is attempting to produce a document store like experience on top of a [SQL](https://en.wikipedia.org/wiki/SQL) database. Every table generated will have a `path_id` which determines it's location in the document hierarchy as well as sub tables will have a `parent_path_id` to associate records with the parent values.
|
|
19
19
|
|
|
20
20
|
Supported features:
|
|
21
|
-
* [CRUD](https://github.com/travetto/travetto/tree/main/module/model/src/
|
|
22
|
-
* [Bulk](https://github.com/travetto/travetto/tree/main/module/model/src/
|
|
23
|
-
* [Query Crud](https://github.com/travetto/travetto/tree/main/module/model-query/src/
|
|
24
|
-
* [Facet](https://github.com/travetto/travetto/tree/main/module/model-query/src/
|
|
25
|
-
* [Query](https://github.com/travetto/travetto/tree/main/module/model-query/src/
|
|
26
|
-
* [Suggest](https://github.com/travetto/travetto/tree/main/module/model-query/src/
|
|
21
|
+
* [CRUD](https://github.com/travetto/travetto/tree/main/module/model/src/types/crud.ts#L11)
|
|
22
|
+
* [Bulk](https://github.com/travetto/travetto/tree/main/module/model/src/types/bulk.ts#L64)
|
|
23
|
+
* [Query Crud](https://github.com/travetto/travetto/tree/main/module/model-query/src/types/crud.ts#L11)
|
|
24
|
+
* [Facet](https://github.com/travetto/travetto/tree/main/module/model-query/src/types/facet.ts#L14)
|
|
25
|
+
* [Query](https://github.com/travetto/travetto/tree/main/module/model-query/src/types/query.ts#L10)
|
|
26
|
+
* [Suggest](https://github.com/travetto/travetto/tree/main/module/model-query/src/types/suggest.ts#L12)
|
|
27
27
|
Out of the box, by installing the module, everything should be wired up by default.If you need to customize any aspect of the source or config, you can override and register it with the [Dependency Injection](https://github.com/travetto/travetto/tree/main/module/di#readme "Dependency registration/management and injection support.") module.
|
|
28
28
|
|
|
29
29
|
**Code: Wiring up a custom Model Source**
|
|
@@ -46,12 +46,6 @@ where the [SQLModelConfig](https://github.com/travetto/travetto/tree/main/module
|
|
|
46
46
|
|
|
47
47
|
**Code: Structure of SQLModelConfig**
|
|
48
48
|
```typescript
|
|
49
|
-
import { Config } from '@travetto/config';
|
|
50
|
-
import { asFull } from '@travetto/runtime';
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* SQL Model Config
|
|
54
|
-
*/
|
|
55
49
|
@Config('model.sql')
|
|
56
50
|
export class SQLModelConfig<T extends {} = {}> {
|
|
57
51
|
/**
|
package/__index__.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './src/dialect';
|
|
2
|
-
export * from './src/connection';
|
|
1
|
+
export * from './src/dialect.ts';
|
|
2
|
+
export * from './src/connection.ts';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/model-mysql",
|
|
3
|
-
"version": "6.0.0-rc.
|
|
3
|
+
"version": "6.0.0-rc.2",
|
|
4
4
|
"description": "MySQL backing for the travetto model module, with real-time modeling support for SQL schemas.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sql",
|
|
@@ -27,13 +27,13 @@
|
|
|
27
27
|
"directory": "module/model-mysql"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@travetto/cli": "^6.0.0-rc.
|
|
31
|
-
"@travetto/config": "^6.0.0-rc.
|
|
32
|
-
"@travetto/context": "^6.0.0-rc.
|
|
33
|
-
"@travetto/model": "^6.0.0-rc.
|
|
34
|
-
"@travetto/model-query": "^6.0.0-rc.
|
|
35
|
-
"@travetto/model-sql": "^6.0.0-rc.
|
|
36
|
-
"mysql2": "^3.
|
|
30
|
+
"@travetto/cli": "^6.0.0-rc.2",
|
|
31
|
+
"@travetto/config": "^6.0.0-rc.2",
|
|
32
|
+
"@travetto/context": "^6.0.0-rc.2",
|
|
33
|
+
"@travetto/model": "^6.0.0-rc.2",
|
|
34
|
+
"@travetto/model-query": "^6.0.0-rc.2",
|
|
35
|
+
"@travetto/model-sql": "^6.0.0-rc.2",
|
|
36
|
+
"mysql2": "^3.14.0"
|
|
37
37
|
},
|
|
38
38
|
"travetto": {
|
|
39
39
|
"displayName": "MySQL Model Service"
|
package/src/connection.ts
CHANGED
|
@@ -48,15 +48,15 @@ export class MySQLConnection extends Connection<PoolConnection> {
|
|
|
48
48
|
* Support some basic type support for JSON data
|
|
49
49
|
*/
|
|
50
50
|
typeCast(field: unknown, next: () => unknown): unknown {
|
|
51
|
-
const
|
|
52
|
-
if (typeof
|
|
53
|
-
if (
|
|
51
|
+
const result = next();
|
|
52
|
+
if (typeof result === 'string' && (field && typeof field === 'object' && 'type' in field) && (field.type === 'JSON' || field.type === 'BLOB')) {
|
|
53
|
+
if (result.charAt(0) === '{' && result.charAt(result.length - 1) === '}') {
|
|
54
54
|
try {
|
|
55
|
-
return JSON.parse(
|
|
55
|
+
return JSON.parse(result);
|
|
56
56
|
} catch { }
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
return
|
|
59
|
+
return result;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
async execute<T = unknown>(conn: PoolConnection, query: string, values?: unknown[]): Promise<{ count: number, records: T[] }> {
|
package/src/dialect.ts
CHANGED
|
@@ -4,10 +4,9 @@ import { AsyncContext } from '@travetto/context';
|
|
|
4
4
|
import { WhereClause } from '@travetto/model-query';
|
|
5
5
|
import { castTo, Class } from '@travetto/runtime';
|
|
6
6
|
import { ModelType } from '@travetto/model';
|
|
7
|
-
import { SQLModelConfig, SQLDialect } from '@travetto/model-sql';
|
|
8
|
-
import { VisitStack } from '@travetto/model-sql/src/internal/util';
|
|
7
|
+
import { SQLModelConfig, SQLDialect, VisitStack } from '@travetto/model-sql';
|
|
9
8
|
|
|
10
|
-
import { MySQLConnection } from './connection';
|
|
9
|
+
import { MySQLConnection } from './connection.ts';
|
|
11
10
|
|
|
12
11
|
/**
|
|
13
12
|
* MYSQL Dialect for the SQL Model Source
|