@memberjunction/sqlserver-dataprovider 1.0.4 → 1.0.7-next.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/SQLServerDataProvider.js +109 -109
- package/package.json +32 -32
|
@@ -377,15 +377,15 @@ class SQLServerDataProvider extends core_1.ProviderBase {
|
|
|
377
377
|
}
|
|
378
378
|
async executeSQLForUserViewRunLogging(viewId, entityBaseView, whereSQL, orderBySQL, user) {
|
|
379
379
|
const entityInfo = this.Entities.find((e) => e.BaseView.trim().toLowerCase() === entityBaseView.trim().toLowerCase());
|
|
380
|
-
const sSQL = `
|
|
381
|
-
DECLARE @ViewIDList TABLE ( ID NVARCHAR(255) );
|
|
382
|
-
INSERT INTO @ViewIDList (ID) (SELECT ${entityInfo.PrimaryKey.Name} FROM [${entityInfo.SchemaName}].${entityBaseView} WHERE (${whereSQL}))
|
|
383
|
-
EXEC [${this.MJCoreSchemaName}].spCreateUserViewRunWithDetail(${viewId},${user.Email}, @ViewIDLIst)
|
|
380
|
+
const sSQL = `
|
|
381
|
+
DECLARE @ViewIDList TABLE ( ID NVARCHAR(255) );
|
|
382
|
+
INSERT INTO @ViewIDList (ID) (SELECT ${entityInfo.PrimaryKey.Name} FROM [${entityInfo.SchemaName}].${entityBaseView} WHERE (${whereSQL}))
|
|
383
|
+
EXEC [${this.MJCoreSchemaName}].spCreateUserViewRunWithDetail(${viewId},${user.Email}, @ViewIDLIst)
|
|
384
384
|
`;
|
|
385
385
|
const runIDResult = await this._dataSource.query(sSQL);
|
|
386
386
|
const runID = runIDResult[0].UserViewRunID;
|
|
387
|
-
const sRetSQL = `SELECT * FROM [${entityInfo.SchemaName}].${entityBaseView} WHERE ${entityInfo.PrimaryKey.Name} IN
|
|
388
|
-
(SELECT RecordID FROM [${this.MJCoreSchemaName}].vwUserViewRunDetails WHERE UserViewRunID=${runID})
|
|
387
|
+
const sRetSQL = `SELECT * FROM [${entityInfo.SchemaName}].${entityBaseView} WHERE ${entityInfo.PrimaryKey.Name} IN
|
|
388
|
+
(SELECT RecordID FROM [${this.MJCoreSchemaName}].vwUserViewRunDetails WHERE UserViewRunID=${runID})
|
|
389
389
|
${orderBySQL && orderBySQL.length > 0 ? ' ORDER BY ' + orderBySQL : ''}`;
|
|
390
390
|
return { executeViewSQL: sRetSQL, runID: runID };
|
|
391
391
|
}
|
|
@@ -579,14 +579,14 @@ class SQLServerDataProvider extends core_1.ProviderBase {
|
|
|
579
579
|
const relatedEntityInfo = this.Entities.find((e) => e.Name.trim().toLowerCase() === entityDependency.RelatedEntityName?.trim().toLowerCase());
|
|
580
580
|
if (sSQL.length > 0)
|
|
581
581
|
sSQL += ' UNION ALL ';
|
|
582
|
-
sSQL += `SELECT
|
|
583
|
-
'${entityDependency.EntityName}' AS EntityName,
|
|
584
|
-
'${entityDependency.RelatedEntityName}' AS RelatedEntityName,
|
|
585
|
-
${entityInfo.PrimaryKeys.map(pk => pk.Name).join(',') /*Add in all pkeys, often just one, but this handles N primary keys*/},
|
|
586
|
-
'${entityDependency.FieldName}' AS FieldName
|
|
587
|
-
FROM
|
|
588
|
-
[${relatedEntityInfo.SchemaName}].${relatedEntityInfo.BaseView}
|
|
589
|
-
WHERE
|
|
582
|
+
sSQL += `SELECT
|
|
583
|
+
'${entityDependency.EntityName}' AS EntityName,
|
|
584
|
+
'${entityDependency.RelatedEntityName}' AS RelatedEntityName,
|
|
585
|
+
${entityInfo.PrimaryKeys.map(pk => pk.Name).join(',') /*Add in all pkeys, often just one, but this handles N primary keys*/},
|
|
586
|
+
'${entityDependency.FieldName}' AS FieldName
|
|
587
|
+
FROM
|
|
588
|
+
[${relatedEntityInfo.SchemaName}].${relatedEntityInfo.BaseView}
|
|
589
|
+
WHERE
|
|
590
590
|
${entityDependency.FieldName} = ${this.GetRecordDependencyLinkSQL(entityDependency, entityInfo, relatedEntityInfo, primaryKeyValues)}`;
|
|
591
591
|
}
|
|
592
592
|
// now, execute the query
|
|
@@ -798,26 +798,26 @@ class SQLServerDataProvider extends core_1.ProviderBase {
|
|
|
798
798
|
let oldData = null;
|
|
799
799
|
if (!bNewRecord)
|
|
800
800
|
oldData = entity.GetAll(true); // get all the OLD values, only do for existing records, for new records, not relevant
|
|
801
|
-
sSQL = `
|
|
802
|
-
DECLARE @ResultTable TABLE (
|
|
803
|
-
${this.getAllEntityColumnsSQL(entity.EntityInfo)}
|
|
804
|
-
)
|
|
805
|
-
|
|
806
|
-
INSERT INTO @ResultTable
|
|
807
|
-
${sSimpleSQL}
|
|
808
|
-
|
|
809
|
-
DECLARE @ID NVARCHAR(255)
|
|
810
|
-
SELECT @ID = ${entity.PrimaryKey.Name} FROM @ResultTable
|
|
811
|
-
IF @ID IS NOT NULL
|
|
812
|
-
BEGIN
|
|
813
|
-
DECLARE @ResultChangesTable TABLE (
|
|
814
|
-
${this.getAllEntityColumnsSQL(recordChangesEntityInfo)}
|
|
815
|
-
)
|
|
816
|
-
|
|
817
|
-
INSERT INTO @ResultChangesTable
|
|
818
|
-
${this.GetLogRecordChangeSQL(entity.GetAll(false), oldData, entity.EntityInfo.Name, '@ID', entity.EntityInfo, user, false)}
|
|
819
|
-
END
|
|
820
|
-
|
|
801
|
+
sSQL = `
|
|
802
|
+
DECLARE @ResultTable TABLE (
|
|
803
|
+
${this.getAllEntityColumnsSQL(entity.EntityInfo)}
|
|
804
|
+
)
|
|
805
|
+
|
|
806
|
+
INSERT INTO @ResultTable
|
|
807
|
+
${sSimpleSQL}
|
|
808
|
+
|
|
809
|
+
DECLARE @ID NVARCHAR(255)
|
|
810
|
+
SELECT @ID = ${entity.PrimaryKey.Name} FROM @ResultTable
|
|
811
|
+
IF @ID IS NOT NULL
|
|
812
|
+
BEGIN
|
|
813
|
+
DECLARE @ResultChangesTable TABLE (
|
|
814
|
+
${this.getAllEntityColumnsSQL(recordChangesEntityInfo)}
|
|
815
|
+
)
|
|
816
|
+
|
|
817
|
+
INSERT INTO @ResultChangesTable
|
|
818
|
+
${this.GetLogRecordChangeSQL(entity.GetAll(false), oldData, entity.EntityInfo.Name, '@ID', entity.EntityInfo, user, false)}
|
|
819
|
+
END
|
|
820
|
+
|
|
821
821
|
SELECT * FROM @ResultTable`;
|
|
822
822
|
}
|
|
823
823
|
else {
|
|
@@ -1027,13 +1027,13 @@ class SQLServerDataProvider extends core_1.ProviderBase {
|
|
|
1027
1027
|
if (changesKeys.length > 0 || oldData === null /*new record*/ || newData === null /*deleted record*/) {
|
|
1028
1028
|
const changesJSON = changes !== null ? JSON.stringify(changes) : '';
|
|
1029
1029
|
const quotes = wrapRecordIdInQuotes ? "'" : '';
|
|
1030
|
-
const sSQL = `EXEC [${this.MJCoreSchemaName}].spCreateRecordChange @EntityName='${entityName}',
|
|
1031
|
-
@RecordID=${quotes}${recordID}${quotes},
|
|
1032
|
-
@UserID=${user.ID},
|
|
1033
|
-
@ChangesJSON='${changesJSON}',
|
|
1034
|
-
@ChangesDescription='${oldData && newData ? this.CreateUserDescription(changes) : !oldData ? 'Record Created' : 'Record Deleted'}',
|
|
1035
|
-
@FullRecordJSON='${fullRecordJSON}',
|
|
1036
|
-
@Status='Complete',
|
|
1030
|
+
const sSQL = `EXEC [${this.MJCoreSchemaName}].spCreateRecordChange @EntityName='${entityName}',
|
|
1031
|
+
@RecordID=${quotes}${recordID}${quotes},
|
|
1032
|
+
@UserID=${user.ID},
|
|
1033
|
+
@ChangesJSON='${changesJSON}',
|
|
1034
|
+
@ChangesDescription='${oldData && newData ? this.CreateUserDescription(changes) : !oldData ? 'Record Created' : 'Record Deleted'}',
|
|
1035
|
+
@FullRecordJSON='${fullRecordJSON}',
|
|
1036
|
+
@Status='Complete',
|
|
1037
1037
|
@Comments=null`;
|
|
1038
1038
|
return sSQL;
|
|
1039
1039
|
}
|
|
@@ -1152,21 +1152,21 @@ class SQLServerDataProvider extends core_1.ProviderBase {
|
|
|
1152
1152
|
const quotes = entity.PrimaryKey.NeedsQuotes ? "'" : '';
|
|
1153
1153
|
if (relInfo.Type.trim().toLowerCase() === 'one to many')
|
|
1154
1154
|
// one to many - simple query
|
|
1155
|
-
relSql = ` SELECT
|
|
1156
|
-
*
|
|
1157
|
-
FROM
|
|
1158
|
-
[${relEntitySchemaName}].[${relInfo.RelatedEntityBaseView}]
|
|
1159
|
-
WHERE
|
|
1155
|
+
relSql = ` SELECT
|
|
1156
|
+
*
|
|
1157
|
+
FROM
|
|
1158
|
+
[${relEntitySchemaName}].[${relInfo.RelatedEntityBaseView}]
|
|
1159
|
+
WHERE
|
|
1160
1160
|
[${relInfo.RelatedEntityJoinField}] = ${quotes}${ret[entity.PrimaryKey.Name]}${quotes}`; // don't yet support composite foreign keys
|
|
1161
1161
|
else
|
|
1162
1162
|
// many to many - need to use join view
|
|
1163
|
-
relSql = ` SELECT
|
|
1164
|
-
_theview.*
|
|
1165
|
-
FROM
|
|
1166
|
-
[${relEntitySchemaName}].[${relInfo.RelatedEntityBaseView}] _theview
|
|
1167
|
-
INNER JOIN
|
|
1168
|
-
[${relEntitySchemaName}].[${relInfo.JoinView}] _jv ON _theview.[${relInfo.RelatedEntityJoinField}] = _jv.[${relInfo.JoinEntityInverseJoinField}]
|
|
1169
|
-
WHERE
|
|
1163
|
+
relSql = ` SELECT
|
|
1164
|
+
_theview.*
|
|
1165
|
+
FROM
|
|
1166
|
+
[${relEntitySchemaName}].[${relInfo.RelatedEntityBaseView}] _theview
|
|
1167
|
+
INNER JOIN
|
|
1168
|
+
[${relEntitySchemaName}].[${relInfo.JoinView}] _jv ON _theview.[${relInfo.RelatedEntityJoinField}] = _jv.[${relInfo.JoinEntityInverseJoinField}]
|
|
1169
|
+
WHERE
|
|
1170
1170
|
_jv.${relInfo.JoinEntityJoinField} = ${quotes}${ret[entity.PrimaryKey.Name]}${quotes}`; // don't yet support composite foreign keys
|
|
1171
1171
|
const relData = await this.ExecuteSQL(relSql);
|
|
1172
1172
|
if (relData && relData.length > 0) {
|
|
@@ -1207,29 +1207,29 @@ class SQLServerDataProvider extends core_1.ProviderBase {
|
|
|
1207
1207
|
const sReturnList = entity.PrimaryKeys.map((pk) => {
|
|
1208
1208
|
return `@${pk.CodeName} AS [${pk.Name}]`;
|
|
1209
1209
|
}).join(', ');
|
|
1210
|
-
sSQL = `
|
|
1211
|
-
IF OBJECT_ID('tempdb..#ResultTable') IS NOT NULL
|
|
1212
|
-
DROP TABLE #ResultTable
|
|
1213
|
-
|
|
1214
|
-
DECLARE @ResultTable TABLE (
|
|
1215
|
-
${sTableDeclare}
|
|
1216
|
-
)
|
|
1217
|
-
|
|
1218
|
-
INSERT INTO @ResultTable
|
|
1219
|
-
${sSimpleSQL}
|
|
1220
|
-
|
|
1221
|
-
DECLARE ${sVariableDeclare}
|
|
1222
|
-
SELECT ${sSelectDeclare} FROM @ResultTable
|
|
1223
|
-
IF ${sIF}
|
|
1224
|
-
BEGIN
|
|
1225
|
-
DECLARE @ResultChangesTable TABLE (
|
|
1226
|
-
${this.getAllEntityColumnsSQL(recordChangesEntityInfo)}
|
|
1227
|
-
)
|
|
1228
|
-
|
|
1229
|
-
INSERT INTO @ResultChangesTable
|
|
1230
|
-
${this.GetLogRecordChangeSQL(null /*pass in null for new data for deleted records*/, oldData, entity.EntityInfo.Name, sCombinedPrimaryKey, entity.EntityInfo, user, true)}
|
|
1231
|
-
END
|
|
1232
|
-
|
|
1210
|
+
sSQL = `
|
|
1211
|
+
IF OBJECT_ID('tempdb..#ResultTable') IS NOT NULL
|
|
1212
|
+
DROP TABLE #ResultTable
|
|
1213
|
+
|
|
1214
|
+
DECLARE @ResultTable TABLE (
|
|
1215
|
+
${sTableDeclare}
|
|
1216
|
+
)
|
|
1217
|
+
|
|
1218
|
+
INSERT INTO @ResultTable
|
|
1219
|
+
${sSimpleSQL}
|
|
1220
|
+
|
|
1221
|
+
DECLARE ${sVariableDeclare}
|
|
1222
|
+
SELECT ${sSelectDeclare} FROM @ResultTable
|
|
1223
|
+
IF ${sIF}
|
|
1224
|
+
BEGIN
|
|
1225
|
+
DECLARE @ResultChangesTable TABLE (
|
|
1226
|
+
${this.getAllEntityColumnsSQL(recordChangesEntityInfo)}
|
|
1227
|
+
)
|
|
1228
|
+
|
|
1229
|
+
INSERT INTO @ResultChangesTable
|
|
1230
|
+
${this.GetLogRecordChangeSQL(null /*pass in null for new data for deleted records*/, oldData, entity.EntityInfo.Name, sCombinedPrimaryKey, entity.EntityInfo, user, true)}
|
|
1231
|
+
END
|
|
1232
|
+
|
|
1233
1233
|
SELECT ${sReturnList}`;
|
|
1234
1234
|
}
|
|
1235
1235
|
else {
|
|
@@ -1295,22 +1295,22 @@ class SQLServerDataProvider extends core_1.ProviderBase {
|
|
|
1295
1295
|
// START ---- IMetadataProvider
|
|
1296
1296
|
/**************************************************************************/
|
|
1297
1297
|
async GetDatasetByName(datasetName, itemFilters) {
|
|
1298
|
-
const sSQL = `SELECT
|
|
1299
|
-
d.ID DatasetID,
|
|
1300
|
-
di.*,
|
|
1301
|
-
e.BaseView EntityBaseView,
|
|
1302
|
-
e.SchemaName EntitySchemaName
|
|
1303
|
-
FROM
|
|
1304
|
-
[${this.MJCoreSchemaName}].vwDatasets d
|
|
1305
|
-
INNER JOIN
|
|
1306
|
-
[${this.MJCoreSchemaName}].vwDatasetItems di
|
|
1307
|
-
ON
|
|
1308
|
-
d.Name = di.DatasetName
|
|
1309
|
-
INNER JOIN
|
|
1310
|
-
[${this.MJCoreSchemaName}].vwEntities e
|
|
1311
|
-
ON
|
|
1312
|
-
di.EntityID = e.ID
|
|
1313
|
-
WHERE
|
|
1298
|
+
const sSQL = `SELECT
|
|
1299
|
+
d.ID DatasetID,
|
|
1300
|
+
di.*,
|
|
1301
|
+
e.BaseView EntityBaseView,
|
|
1302
|
+
e.SchemaName EntitySchemaName
|
|
1303
|
+
FROM
|
|
1304
|
+
[${this.MJCoreSchemaName}].vwDatasets d
|
|
1305
|
+
INNER JOIN
|
|
1306
|
+
[${this.MJCoreSchemaName}].vwDatasetItems di
|
|
1307
|
+
ON
|
|
1308
|
+
d.Name = di.DatasetName
|
|
1309
|
+
INNER JOIN
|
|
1310
|
+
[${this.MJCoreSchemaName}].vwEntities e
|
|
1311
|
+
ON
|
|
1312
|
+
di.EntityID = e.ID
|
|
1313
|
+
WHERE
|
|
1314
1314
|
d.Name = @0`;
|
|
1315
1315
|
const items = await this.ExecuteSQL(sSQL, [datasetName]);
|
|
1316
1316
|
// now we have the dataset and the items, we need to get the update date from the items underlying entities
|
|
@@ -1359,23 +1359,23 @@ class SQLServerDataProvider extends core_1.ProviderBase {
|
|
|
1359
1359
|
}
|
|
1360
1360
|
}
|
|
1361
1361
|
async GetDatasetStatusByName(datasetName, itemFilters) {
|
|
1362
|
-
const sSQL = `
|
|
1363
|
-
SELECT
|
|
1364
|
-
d.ID DatasetID,
|
|
1365
|
-
di.*,
|
|
1366
|
-
e.BaseView EntityBaseView,
|
|
1367
|
-
e.SchemaName EntitySchemaName
|
|
1368
|
-
FROM
|
|
1369
|
-
[${this.MJCoreSchemaName}].vwDatasets d
|
|
1370
|
-
INNER JOIN
|
|
1371
|
-
[${this.MJCoreSchemaName}].vwDatasetItems di
|
|
1372
|
-
ON
|
|
1373
|
-
d.Name = di.DatasetName
|
|
1374
|
-
INNER JOIN
|
|
1375
|
-
[${this.MJCoreSchemaName}].vwEntities e
|
|
1376
|
-
ON
|
|
1377
|
-
di.EntityID = e.ID
|
|
1378
|
-
WHERE
|
|
1362
|
+
const sSQL = `
|
|
1363
|
+
SELECT
|
|
1364
|
+
d.ID DatasetID,
|
|
1365
|
+
di.*,
|
|
1366
|
+
e.BaseView EntityBaseView,
|
|
1367
|
+
e.SchemaName EntitySchemaName
|
|
1368
|
+
FROM
|
|
1369
|
+
[${this.MJCoreSchemaName}].vwDatasets d
|
|
1370
|
+
INNER JOIN
|
|
1371
|
+
[${this.MJCoreSchemaName}].vwDatasetItems di
|
|
1372
|
+
ON
|
|
1373
|
+
d.Name = di.DatasetName
|
|
1374
|
+
INNER JOIN
|
|
1375
|
+
[${this.MJCoreSchemaName}].vwEntities e
|
|
1376
|
+
ON
|
|
1377
|
+
di.EntityID = e.ID
|
|
1378
|
+
WHERE
|
|
1379
1379
|
d.Name = @0`;
|
|
1380
1380
|
const items = await this.ExecuteSQL(sSQL, [datasetName]);
|
|
1381
1381
|
// now we have the dataset and the items, we need to get the update date from the items underlying entities
|
package/package.json
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@memberjunction/sqlserver-dataprovider",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "MemberJunction: SQL Server Client Data Provider",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"files": [
|
|
8
|
-
"/dist"
|
|
9
|
-
],
|
|
10
|
-
"scripts": {
|
|
11
|
-
"start": "ts-node-dev src/index.ts",
|
|
12
|
-
"build": "tsc",
|
|
13
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
14
|
-
},
|
|
15
|
-
"author": "MemberJunction.com",
|
|
16
|
-
"license": "ISC",
|
|
17
|
-
"devDependencies": {
|
|
18
|
-
"ts-node-dev": "^2.0.0",
|
|
19
|
-
"typescript": "^5.3.3"
|
|
20
|
-
},
|
|
21
|
-
"dependencies": {
|
|
22
|
-
"@memberjunction/ai": "^1.0.
|
|
23
|
-
"@memberjunction/aiengine": "^1.0.
|
|
24
|
-
"@memberjunction/core": "^1.0.
|
|
25
|
-
"@memberjunction/core-entities": "^1.0.
|
|
26
|
-
"@memberjunction/global": "^1.0.
|
|
27
|
-
"@memberjunction/queue": "^1.0.
|
|
28
|
-
"@memberjunction/ai-vector-dupe": "^1.0.
|
|
29
|
-
"mssql": "^10.0.2",
|
|
30
|
-
"typeorm": "^0.3.20"
|
|
31
|
-
}
|
|
32
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@memberjunction/sqlserver-dataprovider",
|
|
3
|
+
"version": "1.0.7-next.0",
|
|
4
|
+
"description": "MemberJunction: SQL Server Client Data Provider",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"/dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"start": "ts-node-dev src/index.ts",
|
|
12
|
+
"build": "tsc",
|
|
13
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
14
|
+
},
|
|
15
|
+
"author": "MemberJunction.com",
|
|
16
|
+
"license": "ISC",
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"ts-node-dev": "^2.0.0",
|
|
19
|
+
"typescript": "^5.3.3"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@memberjunction/ai": "^1.0.7-next.0",
|
|
23
|
+
"@memberjunction/aiengine": "^1.0.7-next.0",
|
|
24
|
+
"@memberjunction/core": "^1.0.7-next.0",
|
|
25
|
+
"@memberjunction/core-entities": "^1.0.7-next.0",
|
|
26
|
+
"@memberjunction/global": "^1.0.7-next.0",
|
|
27
|
+
"@memberjunction/queue": "^1.0.7-next.0",
|
|
28
|
+
"@memberjunction/ai-vector-dupe": "^1.0.7-next.0",
|
|
29
|
+
"mssql": "^10.0.2",
|
|
30
|
+
"typeorm": "^0.3.20"
|
|
31
|
+
}
|
|
32
|
+
}
|