@neupgroup/mapper 1.6.2 → 1.7.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/dist/cli/create-migration.js +3 -3
- package/dist/fluent-mapper.d.ts +56 -38
- package/dist/fluent-mapper.js +196 -101
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -46,7 +46,7 @@ import { Mapper, TableMigrator } from '@neupgroup/mapper';
|
|
|
46
46
|
export const usesConnection = 'default';
|
|
47
47
|
|
|
48
48
|
export async function up() {
|
|
49
|
-
const schema = Mapper.schema(
|
|
49
|
+
const schema = Mapper.schema('${tableName}');
|
|
50
50
|
schema.useConnection(usesConnection);
|
|
51
51
|
|
|
52
52
|
/**
|
|
@@ -71,9 +71,9 @@ export async function down() {
|
|
|
71
71
|
* DROP SCHEMA (Immediate action)
|
|
72
72
|
* This will drop the schema from the DB and delete the local schema file.
|
|
73
73
|
*/
|
|
74
|
-
const schema = Mapper.schema(
|
|
74
|
+
const schema = Mapper.schema('${tableName}');
|
|
75
75
|
schema.useConnection(usesConnection);
|
|
76
|
-
await schema.
|
|
76
|
+
await schema.drop().exec();
|
|
77
77
|
}
|
|
78
78
|
`;
|
|
79
79
|
fs.writeFileSync(filePath, fileContent.trim());
|
package/dist/fluent-mapper.d.ts
CHANGED
|
@@ -1,20 +1,40 @@
|
|
|
1
|
-
import { Connections, SchemaManager,
|
|
1
|
+
import { Connections, SchemaManager, ConnectionType } from './index.js';
|
|
2
2
|
import { TableMigrator } from './migrator.js';
|
|
3
3
|
export declare class FluentQueryBuilder {
|
|
4
4
|
private mapper;
|
|
5
5
|
private schemaName;
|
|
6
6
|
private query;
|
|
7
|
+
constructor(mapper: any, schemaName: string, connectionName?: string);
|
|
8
|
+
where(field: string, value: any, operator?: string): this;
|
|
9
|
+
whereComplex(raw: string): this;
|
|
10
|
+
whereRaw(raw: string): this;
|
|
11
|
+
limit(n: number): this;
|
|
12
|
+
offset(n: number): this;
|
|
13
|
+
to(update: Record<string, any>): this;
|
|
14
|
+
get(...fields: string[]): any;
|
|
15
|
+
then(onfulfilled?: ((value: any) => any) | null, onrejected?: ((reason: any) => any) | null): Promise<any>;
|
|
16
|
+
getOne(): Promise<Record<string, any> | null>;
|
|
17
|
+
add(data: Record<string, any>): Promise<any>;
|
|
18
|
+
insert(data: Record<string, any>): Promise<any>;
|
|
19
|
+
update(data?: Record<string, any>): Promise<void>;
|
|
20
|
+
delete(): Promise<void>;
|
|
21
|
+
deleteOne(): Promise<void>;
|
|
22
|
+
updateOne(data?: Record<string, any>): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
export declare class FluentSchemaBuilder {
|
|
25
|
+
private mapper;
|
|
26
|
+
private schemaName;
|
|
7
27
|
private _migrator?;
|
|
8
28
|
constructor(mapper: any, schemaName: string, connectionName?: string);
|
|
9
|
-
getDef
|
|
29
|
+
private getDef;
|
|
10
30
|
set fields(config: any);
|
|
31
|
+
structure(config: any): this;
|
|
32
|
+
collection(collectionName: string): this;
|
|
11
33
|
set insertableFields(val: string[]);
|
|
12
34
|
set updatableFields(val: string[]);
|
|
13
35
|
set deleteType(val: 'softDelete' | 'hardDelete');
|
|
14
36
|
set massDeleteAllowed(val: boolean);
|
|
15
37
|
set massEditAllowed(val: boolean);
|
|
16
|
-
structure(config: any): this;
|
|
17
|
-
collection(collectionName: string): this;
|
|
18
38
|
get migrator(): TableMigrator;
|
|
19
39
|
useConnection(name: string): this;
|
|
20
40
|
addColumn(name: string): import("./migrator.js").ColumnBuilder;
|
|
@@ -22,21 +42,6 @@ export declare class FluentQueryBuilder {
|
|
|
22
42
|
dropColumn(name: string): this;
|
|
23
43
|
drop(): this;
|
|
24
44
|
exec(): Promise<void>;
|
|
25
|
-
dropTable(): Promise<void>;
|
|
26
|
-
where(field: string, value: any, operator?: string): this;
|
|
27
|
-
whereComplex(raw: string): this;
|
|
28
|
-
limit(n: number): this;
|
|
29
|
-
offset(n: number): this;
|
|
30
|
-
to(update: Record<string, any>): this;
|
|
31
|
-
get(...fields: string[]): any;
|
|
32
|
-
then(onfulfilled?: ((value: any) => any) | null, onrejected?: ((reason: any) => any) | null): Promise<any>;
|
|
33
|
-
getOne(): Promise<Record<string, any> | null>;
|
|
34
|
-
add(data: Record<string, any>): Promise<any>;
|
|
35
|
-
insert(data: Record<string, any>): Promise<any>;
|
|
36
|
-
update(): Promise<void>;
|
|
37
|
-
delete(): Promise<void>;
|
|
38
|
-
deleteOne(): Promise<void>;
|
|
39
|
-
updateOne(): Promise<void>;
|
|
40
45
|
}
|
|
41
46
|
export declare class FluentConnectionBuilder {
|
|
42
47
|
private mapper;
|
|
@@ -48,24 +53,33 @@ export declare class FluentConnectionBuilder {
|
|
|
48
53
|
query(schemaName: string): FluentQueryBuilder;
|
|
49
54
|
useConnection(connectionName: string): FluentConnectionSelector;
|
|
50
55
|
}
|
|
51
|
-
export declare class
|
|
56
|
+
export declare class RawQueryBuilder {
|
|
52
57
|
private mapper;
|
|
53
|
-
private
|
|
54
|
-
private
|
|
55
|
-
constructor(mapper: any,
|
|
56
|
-
|
|
58
|
+
private sql;
|
|
59
|
+
private _bindings;
|
|
60
|
+
constructor(mapper: any, sql: string);
|
|
61
|
+
bind(bindings: any[] | any): this;
|
|
62
|
+
run(): Promise<any>;
|
|
57
63
|
}
|
|
58
|
-
export declare class
|
|
64
|
+
export declare class BaseQueryBuilder {
|
|
59
65
|
private mapper;
|
|
60
|
-
private
|
|
61
|
-
private
|
|
62
|
-
private
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
private target;
|
|
67
|
+
private queryBuilder;
|
|
68
|
+
private _select;
|
|
69
|
+
private _insertData?;
|
|
70
|
+
private _updateData?;
|
|
71
|
+
private _action;
|
|
72
|
+
constructor(mapper: any, target: string);
|
|
73
|
+
select(fields: string[]): this;
|
|
74
|
+
where(field: string, value: any, operator?: string): this;
|
|
75
|
+
whereRaw(raw: string): this;
|
|
76
|
+
limit(n: number): this;
|
|
77
|
+
offset(n: number): this;
|
|
78
|
+
insert(data: any): this;
|
|
79
|
+
update(data: any): this;
|
|
80
|
+
get(): Promise<any>;
|
|
81
|
+
getOne(): Promise<any>;
|
|
82
|
+
run(): Promise<any>;
|
|
69
83
|
}
|
|
70
84
|
export declare class FluentApiRequestBuilder {
|
|
71
85
|
private mapper;
|
|
@@ -87,8 +101,8 @@ export declare class FluentConnectionSelector {
|
|
|
87
101
|
private mapper;
|
|
88
102
|
private connectionName;
|
|
89
103
|
constructor(mapper: any, connectionName: string);
|
|
90
|
-
schema(schemaName: string):
|
|
91
|
-
schemas(schemaName: string):
|
|
104
|
+
schema(schemaName: string): FluentSchemaBuilder;
|
|
105
|
+
schemas(schemaName: string): FluentSchemaBuilder;
|
|
92
106
|
query(schemaName: string): FluentQueryBuilder;
|
|
93
107
|
table(tableName: string): FluentQueryBuilder;
|
|
94
108
|
collection(collectionName: string): FluentQueryBuilder;
|
|
@@ -105,8 +119,10 @@ export declare class FluentMapper {
|
|
|
105
119
|
private mapper;
|
|
106
120
|
constructor(mapper: any);
|
|
107
121
|
query(schemaName: string): FluentQueryBuilder;
|
|
108
|
-
schema(name: string):
|
|
122
|
+
schema(name: string): FluentSchemaBuilder;
|
|
109
123
|
table(name: string): FluentQueryBuilder;
|
|
124
|
+
raw(sql: string): RawQueryBuilder;
|
|
125
|
+
base(target: string): BaseQueryBuilder;
|
|
110
126
|
makeConnection(name: string, type: ConnectionType, config: Record<string, any>): FluentConnectionBuilder;
|
|
111
127
|
useConnection(connectionName: string): FluentConnectionSelector;
|
|
112
128
|
connection(connectionOrConfig: string | Record<string, any>): FluentConnectionSelector;
|
|
@@ -124,9 +140,11 @@ export declare class StaticMapper {
|
|
|
124
140
|
static makeConnection(name: string, type: ConnectionType, config: Record<string, any>): FluentConnectionBuilder;
|
|
125
141
|
static makeTempConnection(type: ConnectionType, config: Record<string, any>): FluentConnectionBuilder;
|
|
126
142
|
static query(schemaName: string): FluentQueryBuilder;
|
|
127
|
-
static schema(name: string):
|
|
143
|
+
static schema(name: string): FluentSchemaBuilder;
|
|
128
144
|
static schema(): SchemaManagerWrapper;
|
|
129
145
|
static table(name: string): FluentQueryBuilder;
|
|
146
|
+
static raw(sql: string): RawQueryBuilder;
|
|
147
|
+
static base(target: string): BaseQueryBuilder;
|
|
130
148
|
static connection(connectionOrConfig: string | Record<string, any>): FluentConnectionSelector;
|
|
131
149
|
static useConnection(connectionName: string): FluentConnectionSelector;
|
|
132
150
|
static schemas(name?: string): any;
|
package/dist/fluent-mapper.js
CHANGED
|
@@ -1,26 +1,107 @@
|
|
|
1
1
|
import { createMapper } from './mapper.js';
|
|
2
2
|
import { TableMigrator } from './migrator.js';
|
|
3
|
+
// DML Builder (Querying)
|
|
3
4
|
export class FluentQueryBuilder {
|
|
4
5
|
constructor(mapper, schemaName, connectionName) {
|
|
5
6
|
this.mapper = mapper;
|
|
6
7
|
this.schemaName = schemaName;
|
|
7
8
|
try {
|
|
8
9
|
this.query = mapper.use(schemaName);
|
|
10
|
+
// Auto-update connection if provided override
|
|
9
11
|
if (connectionName) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def.connectionName = connectionName;
|
|
12
|
+
// We can't easily update the schema def from query builder purely,
|
|
13
|
+
// but the Use() call presumably set up the schemaQuery.
|
|
13
14
|
}
|
|
14
15
|
}
|
|
15
16
|
catch (e) {
|
|
16
|
-
// Auto-register schema if missing
|
|
17
|
+
// Auto-register schema if missing
|
|
17
18
|
mapper.getSchemaManager().create(schemaName).use({ connection: connectionName || 'default', collection: schemaName }).setStructure({});
|
|
18
19
|
this.query = mapper.use(schemaName);
|
|
19
20
|
}
|
|
20
21
|
}
|
|
22
|
+
where(field, value, operator) {
|
|
23
|
+
this.query.where(field, value, operator);
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
whereComplex(raw) {
|
|
27
|
+
this.query.whereComplex(raw);
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
whereRaw(raw) {
|
|
31
|
+
return this.whereComplex(raw);
|
|
32
|
+
}
|
|
33
|
+
limit(n) {
|
|
34
|
+
this.query.limit(n);
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
offset(n) {
|
|
38
|
+
this.query.offset(n);
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
to(update) {
|
|
42
|
+
this.query.to(update);
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
get(...fields) {
|
|
46
|
+
if (fields.length > 0) {
|
|
47
|
+
this.query.selectFields(fields);
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
return this.query.get();
|
|
51
|
+
}
|
|
52
|
+
then(onfulfilled, onrejected) {
|
|
53
|
+
return this.query.get().then(onfulfilled, onrejected);
|
|
54
|
+
}
|
|
55
|
+
async getOne() {
|
|
56
|
+
return this.query.getOne();
|
|
57
|
+
}
|
|
58
|
+
async add(data) {
|
|
59
|
+
return this.mapper.add(this.schemaName, data);
|
|
60
|
+
}
|
|
61
|
+
async insert(data) {
|
|
62
|
+
return this.add(data);
|
|
63
|
+
}
|
|
64
|
+
async update(data) {
|
|
65
|
+
if (data) {
|
|
66
|
+
this.query.to(data);
|
|
67
|
+
}
|
|
68
|
+
return this.query.update();
|
|
69
|
+
}
|
|
70
|
+
async delete() {
|
|
71
|
+
return this.query.delete();
|
|
72
|
+
}
|
|
73
|
+
async deleteOne() {
|
|
74
|
+
return this.query.deleteOne();
|
|
75
|
+
}
|
|
76
|
+
async updateOne(data) {
|
|
77
|
+
if (data) {
|
|
78
|
+
this.query.to(data);
|
|
79
|
+
}
|
|
80
|
+
return this.query.updateOne();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// DDL Builder (Migrations & Schema Definition)
|
|
84
|
+
export class FluentSchemaBuilder {
|
|
85
|
+
constructor(mapper, schemaName, connectionName) {
|
|
86
|
+
this.mapper = mapper;
|
|
87
|
+
this.schemaName = schemaName;
|
|
88
|
+
// Ensure schema exists for configuration
|
|
89
|
+
const manager = mapper.getSchemaManager();
|
|
90
|
+
const exists = manager.schemas.has(schemaName);
|
|
91
|
+
if (!exists) {
|
|
92
|
+
manager.create(schemaName).use({ connection: connectionName || 'default', collection: schemaName }).setStructure({});
|
|
93
|
+
}
|
|
94
|
+
// If connectionName provided, update it
|
|
95
|
+
if (connectionName) {
|
|
96
|
+
const def = this.getDef();
|
|
97
|
+
if (def)
|
|
98
|
+
def.connectionName = connectionName;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
21
101
|
getDef() {
|
|
22
102
|
return this.mapper.getSchemaManager().schemas.get(this.schemaName);
|
|
23
103
|
}
|
|
104
|
+
// Schema Configuration Proxies
|
|
24
105
|
set fields(config) {
|
|
25
106
|
const def = this.getDef();
|
|
26
107
|
if (def) {
|
|
@@ -31,6 +112,16 @@ export class FluentQueryBuilder {
|
|
|
31
112
|
def.allowUndefinedFields = parsed.allowUndefinedFields;
|
|
32
113
|
}
|
|
33
114
|
}
|
|
115
|
+
structure(config) {
|
|
116
|
+
this.fields = config;
|
|
117
|
+
return this;
|
|
118
|
+
}
|
|
119
|
+
collection(collectionName) {
|
|
120
|
+
const def = this.getDef();
|
|
121
|
+
if (def)
|
|
122
|
+
def.collectionName = collectionName;
|
|
123
|
+
return this;
|
|
124
|
+
}
|
|
34
125
|
set insertableFields(val) {
|
|
35
126
|
const def = this.getDef();
|
|
36
127
|
if (def)
|
|
@@ -56,20 +147,10 @@ export class FluentQueryBuilder {
|
|
|
56
147
|
if (def)
|
|
57
148
|
def.massEditAllowed = val;
|
|
58
149
|
}
|
|
59
|
-
|
|
60
|
-
this.fields = config;
|
|
61
|
-
return this;
|
|
62
|
-
}
|
|
63
|
-
collection(collectionName) {
|
|
64
|
-
const def = this.getDef();
|
|
65
|
-
if (def)
|
|
66
|
-
def.collectionName = collectionName;
|
|
67
|
-
return this;
|
|
68
|
-
}
|
|
150
|
+
// Migration / DDL Methods
|
|
69
151
|
get migrator() {
|
|
70
152
|
if (!this._migrator) {
|
|
71
153
|
this._migrator = new TableMigrator(this.schemaName);
|
|
72
|
-
// Sync connection if already set on query
|
|
73
154
|
const def = this.getDef();
|
|
74
155
|
if (def === null || def === void 0 ? void 0 : def.connectionName) {
|
|
75
156
|
this._migrator.useConnection(def.connectionName);
|
|
@@ -77,7 +158,6 @@ export class FluentQueryBuilder {
|
|
|
77
158
|
}
|
|
78
159
|
return this._migrator;
|
|
79
160
|
}
|
|
80
|
-
// Migration/DDL Methods (Proxied to internal migrator)
|
|
81
161
|
useConnection(name) {
|
|
82
162
|
this.migrator.useConnection(name);
|
|
83
163
|
const def = this.getDef();
|
|
@@ -92,69 +172,6 @@ export class FluentQueryBuilder {
|
|
|
92
172
|
async exec() {
|
|
93
173
|
return this.migrator.exec();
|
|
94
174
|
}
|
|
95
|
-
async dropTable() {
|
|
96
|
-
return this.migrator.drop().exec();
|
|
97
|
-
}
|
|
98
|
-
where(field, value, operator) {
|
|
99
|
-
this.query.where(field, value, operator);
|
|
100
|
-
return this;
|
|
101
|
-
}
|
|
102
|
-
whereComplex(raw) {
|
|
103
|
-
this.query.whereComplex(raw);
|
|
104
|
-
return this;
|
|
105
|
-
}
|
|
106
|
-
limit(n) {
|
|
107
|
-
this.query.limit(n);
|
|
108
|
-
return this;
|
|
109
|
-
}
|
|
110
|
-
offset(n) {
|
|
111
|
-
this.query.offset(n);
|
|
112
|
-
return this;
|
|
113
|
-
}
|
|
114
|
-
to(update) {
|
|
115
|
-
this.query.to(update);
|
|
116
|
-
return this;
|
|
117
|
-
}
|
|
118
|
-
// If args provided, act as SELECT (projection) and return this.
|
|
119
|
-
// If no args, act as execute() (but this class is thenable so we can just return this if we want consistency,
|
|
120
|
-
// but existing API returns Promise directly. To check user intent:
|
|
121
|
-
// User: get('f1').limit(1).
|
|
122
|
-
// So get('f1') must return this.
|
|
123
|
-
get(...fields) {
|
|
124
|
-
if (fields.length > 0) {
|
|
125
|
-
// Apply field selection? SchemaQuery needs a way to filter fields.
|
|
126
|
-
// We'll add this capability to Field filtering in SchemaQuery or just use 'fields' option in buildOptions.
|
|
127
|
-
// For now, let's assume we can modify the query's field list.
|
|
128
|
-
this.query.selectFields(fields);
|
|
129
|
-
return this;
|
|
130
|
-
}
|
|
131
|
-
return this.query.get(); // Promise
|
|
132
|
-
}
|
|
133
|
-
// Make the builder thenable
|
|
134
|
-
then(onfulfilled, onrejected) {
|
|
135
|
-
return this.query.get().then(onfulfilled, onrejected);
|
|
136
|
-
}
|
|
137
|
-
async getOne() {
|
|
138
|
-
return this.query.getOne();
|
|
139
|
-
}
|
|
140
|
-
async add(data) {
|
|
141
|
-
return this.mapper.add(this.schemaName, data);
|
|
142
|
-
}
|
|
143
|
-
async insert(data) {
|
|
144
|
-
return this.add(data);
|
|
145
|
-
}
|
|
146
|
-
async update() {
|
|
147
|
-
return this.query.update();
|
|
148
|
-
}
|
|
149
|
-
async delete() {
|
|
150
|
-
return this.query.delete();
|
|
151
|
-
}
|
|
152
|
-
async deleteOne() {
|
|
153
|
-
return this.query.deleteOne();
|
|
154
|
-
}
|
|
155
|
-
async updateOne() {
|
|
156
|
-
return this.query.updateOne();
|
|
157
|
-
}
|
|
158
175
|
}
|
|
159
176
|
export class FluentConnectionBuilder {
|
|
160
177
|
constructor(mapper, connectionName, connectionType, config) {
|
|
@@ -175,28 +192,94 @@ export class FluentConnectionBuilder {
|
|
|
175
192
|
return new FluentConnectionSelector(this.mapper, connectionName);
|
|
176
193
|
}
|
|
177
194
|
}
|
|
178
|
-
export class
|
|
179
|
-
constructor(mapper,
|
|
195
|
+
export class RawQueryBuilder {
|
|
196
|
+
constructor(mapper, sql) {
|
|
180
197
|
this.mapper = mapper;
|
|
181
|
-
this.
|
|
182
|
-
this.
|
|
198
|
+
this.sql = sql;
|
|
199
|
+
this._bindings = [];
|
|
183
200
|
}
|
|
184
|
-
|
|
185
|
-
|
|
201
|
+
bind(bindings) {
|
|
202
|
+
if (Array.isArray(bindings)) {
|
|
203
|
+
this._bindings = bindings;
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
this._bindings = [bindings];
|
|
207
|
+
}
|
|
208
|
+
return this;
|
|
209
|
+
}
|
|
210
|
+
async run() {
|
|
211
|
+
// Find a default connection or use one if specified (not currently supported in raw() entry point args, defaulting to 'default')
|
|
212
|
+
// To support explicit connection for raw, we might need Mapper.connection('name').raw(...)
|
|
213
|
+
const connections = this.mapper.getConnections();
|
|
214
|
+
const conn = connections.get('default'); // Default fallback
|
|
215
|
+
if (!conn)
|
|
216
|
+
throw new Error("No default connection found for raw query.");
|
|
217
|
+
const adapter = connections.getAdapter(conn.name);
|
|
218
|
+
if (adapter && typeof adapter.query === 'function') {
|
|
219
|
+
return adapter.query(this.sql, this._bindings);
|
|
220
|
+
}
|
|
221
|
+
throw new Error(`Connection '${conn.name}' does not support raw queries.`);
|
|
186
222
|
}
|
|
187
223
|
}
|
|
188
|
-
export class
|
|
189
|
-
constructor(mapper,
|
|
224
|
+
export class BaseQueryBuilder {
|
|
225
|
+
constructor(mapper, target) {
|
|
190
226
|
this.mapper = mapper;
|
|
191
|
-
this.
|
|
192
|
-
this.
|
|
193
|
-
this.
|
|
227
|
+
this.target = target;
|
|
228
|
+
this._select = [];
|
|
229
|
+
this._action = 'select';
|
|
230
|
+
this.queryBuilder = new FluentQueryBuilder(mapper, target);
|
|
231
|
+
}
|
|
232
|
+
select(fields) {
|
|
233
|
+
this._select = fields;
|
|
234
|
+
this._action = 'select';
|
|
235
|
+
return this;
|
|
236
|
+
}
|
|
237
|
+
where(field, value, operator) {
|
|
238
|
+
this.queryBuilder.where(field, value, operator);
|
|
239
|
+
return this;
|
|
240
|
+
}
|
|
241
|
+
whereRaw(raw) {
|
|
242
|
+
this.queryBuilder.whereRaw(raw);
|
|
243
|
+
return this;
|
|
244
|
+
}
|
|
245
|
+
limit(n) {
|
|
246
|
+
this.queryBuilder.limit(n);
|
|
247
|
+
return this;
|
|
248
|
+
}
|
|
249
|
+
offset(n) {
|
|
250
|
+
this.queryBuilder.offset(n);
|
|
251
|
+
return this;
|
|
194
252
|
}
|
|
195
|
-
|
|
196
|
-
this.
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
253
|
+
insert(data) {
|
|
254
|
+
this._insertData = data;
|
|
255
|
+
this._action = 'insert';
|
|
256
|
+
return this;
|
|
257
|
+
}
|
|
258
|
+
update(data) {
|
|
259
|
+
this._updateData = data;
|
|
260
|
+
this._action = 'update';
|
|
261
|
+
return this;
|
|
262
|
+
}
|
|
263
|
+
async get() {
|
|
264
|
+
return this.queryBuilder.get(...this._select);
|
|
265
|
+
}
|
|
266
|
+
async getOne() {
|
|
267
|
+
// If select fields were provided, apply them first (though getOne usually fetches all or requires separate select handling in standard query)
|
|
268
|
+
// FluentQueryBuilder.getOne doesn't take args, but we can ensure fields are selected if underlying support exists.
|
|
269
|
+
// Current FluentQueryBuilder doesn't support select() state persistence easily without get() args.
|
|
270
|
+
// We'll proceed with getOne(). To support partial select on getOne, we might need to enhance FluentQueryBuilder or just fetch all.
|
|
271
|
+
// For now, delegating effectively:
|
|
272
|
+
return this.queryBuilder.getOne();
|
|
273
|
+
}
|
|
274
|
+
async run() {
|
|
275
|
+
if (this._action === 'insert') {
|
|
276
|
+
return this.queryBuilder.insert(this._insertData);
|
|
277
|
+
}
|
|
278
|
+
if (this._action === 'update') {
|
|
279
|
+
return this.queryBuilder.update(this._updateData);
|
|
280
|
+
}
|
|
281
|
+
// Fallback or other actions
|
|
282
|
+
return this.get();
|
|
200
283
|
}
|
|
201
284
|
}
|
|
202
285
|
export class FluentApiRequestBuilder {
|
|
@@ -279,19 +362,19 @@ export class FluentConnectionSelector {
|
|
|
279
362
|
this.connectionName = connectionName;
|
|
280
363
|
}
|
|
281
364
|
schema(schemaName) {
|
|
282
|
-
return new
|
|
365
|
+
return new FluentSchemaBuilder(this.mapper, schemaName, this.connectionName);
|
|
283
366
|
}
|
|
284
367
|
schemas(schemaName) {
|
|
285
368
|
return this.schema(schemaName);
|
|
286
369
|
}
|
|
287
370
|
query(schemaName) {
|
|
288
|
-
return this.
|
|
371
|
+
return new FluentQueryBuilder(this.mapper, schemaName, this.connectionName);
|
|
289
372
|
}
|
|
290
373
|
table(tableName) {
|
|
291
|
-
return this.
|
|
374
|
+
return this.query(tableName);
|
|
292
375
|
}
|
|
293
376
|
collection(collectionName) {
|
|
294
|
-
return this.
|
|
377
|
+
return this.query(collectionName);
|
|
295
378
|
}
|
|
296
379
|
// API Request methods
|
|
297
380
|
path(path) {
|
|
@@ -327,11 +410,17 @@ export class FluentMapper {
|
|
|
327
410
|
return new FluentQueryBuilder(this.mapper, schemaName);
|
|
328
411
|
}
|
|
329
412
|
schema(name) {
|
|
330
|
-
return this.
|
|
413
|
+
return new FluentSchemaBuilder(this.mapper, name);
|
|
331
414
|
}
|
|
332
415
|
table(name) {
|
|
333
416
|
return this.query(name);
|
|
334
417
|
}
|
|
418
|
+
raw(sql) {
|
|
419
|
+
return new RawQueryBuilder(this.mapper, sql);
|
|
420
|
+
}
|
|
421
|
+
base(target) {
|
|
422
|
+
return new BaseQueryBuilder(this.mapper, target);
|
|
423
|
+
}
|
|
335
424
|
makeConnection(name, type, config) {
|
|
336
425
|
return new FluentConnectionBuilder(this.mapper, name, type, config);
|
|
337
426
|
}
|
|
@@ -404,7 +493,13 @@ export class StaticMapper {
|
|
|
404
493
|
return StaticMapper.schemas();
|
|
405
494
|
}
|
|
406
495
|
static table(name) {
|
|
407
|
-
return StaticMapper.
|
|
496
|
+
return StaticMapper.query(name);
|
|
497
|
+
}
|
|
498
|
+
static raw(sql) {
|
|
499
|
+
return StaticMapper.getFluentMapper().raw(sql);
|
|
500
|
+
}
|
|
501
|
+
static base(target) {
|
|
502
|
+
return StaticMapper.getFluentMapper().base(target);
|
|
408
503
|
}
|
|
409
504
|
// New API
|
|
410
505
|
static connection(connectionOrConfig) {
|
package/dist/index.d.ts
CHANGED
|
@@ -127,8 +127,8 @@ export type { EnvDslConnections, NormalizedConnection } from './env.js';
|
|
|
127
127
|
export { documentationMd, markdownToHtml, getDocumentationHtml } from './docs.js';
|
|
128
128
|
export { Mapper, createMapper } from './mapper.js';
|
|
129
129
|
export { default } from './mapper.js';
|
|
130
|
-
export { StaticMapper } from './fluent-mapper.js';
|
|
131
|
-
export type { FluentQueryBuilder, FluentConnectionBuilder, FluentSchemaBuilder,
|
|
130
|
+
export { StaticMapper, RawQueryBuilder, BaseQueryBuilder } from './fluent-mapper.js';
|
|
131
|
+
export type { FluentQueryBuilder, FluentConnectionBuilder, FluentSchemaBuilder, FluentConnectionSelector, FluentMapper } from './fluent-mapper.js';
|
|
132
132
|
export { ConfigBasedMapper, ConfigLoader, createConfigMapper, getConfigMapper, createDefaultMapper } from './config.js';
|
|
133
133
|
export type { MapperConfig, ConnectionConfig, DatabaseConnectionConfig, ApiConnectionConfig, SqliteConnectionConfig, ConfigSchema } from './config.js';
|
|
134
134
|
export { MySQLAdapter, createMySQLAdapter, PostgreSQLAdapter, createPostgreSQLAdapter, MongoDBAdapter, createMongoDBAdapter, APIAdapter, createAPIAdapter, SQLiteAdapter, createSQLiteAdapter, createAdapter, createAdapterFromUrl, autoAttachAdapter } from './adapters/index.js';
|
package/dist/index.js
CHANGED
|
@@ -397,7 +397,7 @@ export { documentationMd, markdownToHtml, getDocumentationHtml } from './docs.js
|
|
|
397
397
|
export { Mapper, createMapper } from './mapper.js';
|
|
398
398
|
export { default } from './mapper.js';
|
|
399
399
|
// Export the new fluent/static API
|
|
400
|
-
export { StaticMapper } from './fluent-mapper.js';
|
|
400
|
+
export { StaticMapper, RawQueryBuilder, BaseQueryBuilder } from './fluent-mapper.js';
|
|
401
401
|
// Export the new config-based system
|
|
402
402
|
export { ConfigBasedMapper, ConfigLoader, createConfigMapper, getConfigMapper, createDefaultMapper } from './config.js';
|
|
403
403
|
// Export database adapters
|