@dbpath/tables
Advanced tools
Comparing version 0.2.19 to 0.2.20
@@ -9,3 +9,3 @@ "use strict"; | ||
"columns": [{ "alias": "T0", "column": "*" }], | ||
"tables": [{ "alias": "T0", "table": "someSchema.drivertable" }], | ||
"tables": [{ "schema": "s0", "alias": "T0", "table": "someSchema.drivertable" }], | ||
pk: ['T0.driverId'], | ||
@@ -17,10 +17,14 @@ "where": ["T0.driverid=1"] | ||
expect((0, selectData_1.mergeSelectData)(fixtures_1.selectDataForDriverMissionAuditAndWhere)).toEqual({ | ||
"columns": [{ "alias": "T0", "column": "*" }, | ||
"columns": [ | ||
{ "alias": "T0", "column": "*" }, | ||
{ "alias": "T1", "column": "*" }, | ||
{ "alias": "T2", "column": "f3" }, | ||
{ "alias": "T2", "column": "f4" }], | ||
"tables": [{ "alias": "T0", "table": "someSchema.drivertable" }, | ||
{ "alias": "T1", "table": "someSchema.mission" }, | ||
{ "alias": "T2", "table": "someSchema.audit" }], | ||
pk: ["T0.driverId"], | ||
{ "alias": "T2", "column": "f4" } | ||
], | ||
"pk": ["T0.driverId"], | ||
"tables": [ | ||
{ "alias": "T0", "schema": "s0", "table": "someSchema.drivertable" }, | ||
{ "alias": "T1", "schema": "s1", "table": "someSchema.mission" }, | ||
{ "alias": "T2", "schema": "s2", "table": "someSchema.audit" } | ||
], | ||
"where": ["T0.driverid=1", "T0.id1 = T1.id2", "T1.id2 = T2.id3"] | ||
@@ -27,0 +31,0 @@ }); |
import { Paging } from "@dbpath/types"; | ||
export interface SelectData { | ||
schema: string; | ||
table: string; | ||
@@ -11,2 +12,3 @@ pk: string[]; | ||
tables: { | ||
schema: string; | ||
table: string; | ||
@@ -13,0 +15,0 @@ alias: string; |
@@ -6,3 +6,3 @@ "use strict"; | ||
function mergeSelectData(selectData) { | ||
const tables = selectData.map(s => ({ table: s.table, alias: s.alias })); | ||
const tables = selectData.map(s => ({ schema: s.schema, table: s.table, alias: s.alias })); | ||
const columns = (0, utils_1.flatMap)(selectData, s => s.columns.map(c => ({ alias: s.alias, column: c }))); | ||
@@ -18,3 +18,3 @@ const where = (0, utils_1.flatMap)(selectData, s => s.where).filter(w => w !== undefined); | ||
const columns = count ? 'count(1)' : m.columns.map(c => `${c.alias}.${c.column}`).join(', '); | ||
const tables = m.tables.map(t => `${t.table} ${t.alias}`).join(', '); | ||
const tables = m.tables.map(t => `${t.schema}.${t.table} ${t.alias}`).join(', '); | ||
const where = m.where.length > 0 ? `where ${m.where.join(' and ')}` : ''; | ||
@@ -21,0 +21,0 @@ let orderBy = count ? [] : [`order by ${(0, utils_1.safeArray)(m.pk).join(', ')}`]; |
@@ -16,2 +16,3 @@ "use strict"; | ||
const parts = (0, exports.mapOverPath)(p, p => p); | ||
const schema = pathSpecForWhere.schema; | ||
return parts.map((p, i) => { | ||
@@ -23,4 +24,5 @@ let alias = `T${i}`; | ||
const selectDataForTable = { | ||
schema: p.schema ? p.schema : schema, | ||
columns: p.fields.length > 0 ? p.fields : ['*'], | ||
table: pathSpecForWhere.schema + '.' + p.table, | ||
table: p.table, | ||
alias, | ||
@@ -27,0 +29,0 @@ pk: p.pk, |
@@ -15,21 +15,25 @@ "use strict"; | ||
it("should make an array of select data", () => { | ||
expect((0, sql_1.pathToSelectData)(fixtures_1.driverPath, { schema, table2Pk })).toEqual([ | ||
{ "alias": "T0", "columns": ['*'], "table": "someSchema.drivertable", "pk": ["driverId"], "where": [] } | ||
]); | ||
expect((0, sql_1.pathToSelectData)(fixtures_1.driverPath, { schema, table2Pk })).toEqual([{ | ||
"alias": "T0", | ||
"columns": ["*"], "pk": ["driverId"], | ||
"schema": "someSchema", | ||
"table": "drivertable", | ||
"where": [] | ||
}]); | ||
}); | ||
it("should make an array of select data with id", () => { | ||
expect((0, sql_1.pathToSelectData)(fixtures_1.driverPath, { schema, id: '1', table2Pk })).toEqual([ | ||
{ | ||
expect((0, sql_1.pathToSelectData)(fixtures_1.driverPath, { schema, id: '1', table2Pk })).toEqual([{ | ||
"alias": "T0", | ||
"columns": ["*"], | ||
"table": "someSchema.drivertable", "pk": ["driverId"], | ||
"columns": ["*"], "pk": ["driverId"], | ||
"schema": "someSchema", | ||
"table": "drivertable", | ||
"where": ["T0.driverid=1"] | ||
} | ||
]); | ||
}]); | ||
}); | ||
it("should make an array of select data for driver.mission.audit", () => { | ||
expect((0, sql_1.pathToSelectData)(fixtures_1.driverMissionAuditWithFieldsAndLinksPath, { schema, table2Pk })).toEqual([ | ||
{ "alias": "T0", "columns": ['*'], "table": "someSchema.drivertable", "pk": ["driverId"], "where": [] }, | ||
{ "alias": "T1", "columns": ['*'], "table": "someSchema.mission", "pk": ["id"], "where": ["T0.id1 = T1.id2"] }, | ||
{ "alias": "T2", "columns": ["f3", "f4"], "table": "someSchema.audit", "pk": ["id"], "where": ["T1.id2 = T2.id3"] } | ||
{ "alias": "T0", "columns": ["*"], "pk": ["driverId"], "schema": "someSchema", "table": "drivertable", "where": [] }, | ||
{ "alias": "T1", "columns": ["*"], "pk": ["id"], "schema": "someSchema", "table": "mission", "where": ["T0.id1 = T1.id2"] }, { | ||
"alias": "T2", "columns": ["f3", "f4"], "pk": ["id"], "schema": "someSchema", "table": "audit", "where": ["T1.id2 = T2.id3"] | ||
} | ||
]); | ||
@@ -39,5 +43,5 @@ }); | ||
expect((0, sql_1.pathToSelectData)(fixtures_1.driverMissionAuditWithFieldsAndLinksPath, { schema, id: '1', table2Pk })).toEqual([ | ||
{ "alias": "T0", "columns": ['*'], "table": "someSchema.drivertable", "pk": ["driverId"], "where": ["T0.driverid=1"] }, | ||
{ "alias": "T1", "columns": ['*'], "table": "someSchema.mission", "pk": ["id"], "where": ["T0.id1 = T1.id2"] }, | ||
{ "alias": "T2", "columns": ["f3", "f4"], "table": "someSchema.audit", "pk": ["id"], "where": ["T1.id2 = T2.id3"] } | ||
{ "alias": "T0", "columns": ["*"], "pk": ["driverId"], "schema": "someSchema", "table": "drivertable", "where": ["T0.driverid=1"] }, | ||
{ "alias": "T1", "columns": ["*"], "pk": ["id"], "schema": "someSchema", "table": "mission", "where": ["T0.id1 = T1.id2"] }, | ||
{ "alias": "T2", "columns": ["f3", "f4"], "pk": ["id"], "schema": "someSchema", "table": "audit", "where": ["T1.id2 = T2.id3"] } | ||
]); | ||
@@ -44,0 +48,0 @@ }); |
{ | ||
"name": "@dbpath/tables", | ||
"description": "", | ||
"version": "0.2.19", | ||
"version": "0.2.20", | ||
"main": "dist/index", | ||
@@ -20,5 +20,5 @@ "types": "dist/index", | ||
"dependencies": { | ||
"@dbpath/utils": "0.2.19", | ||
"@dbpath/types": "0.2.19", | ||
"@dbpath/fixtures": "0.2.19" | ||
"@dbpath/utils": "0.2.20", | ||
"@dbpath/types": "0.2.20", | ||
"@dbpath/fixtures": "0.2.20" | ||
}, | ||
@@ -25,0 +25,0 @@ "devDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20022
366
+ Added@dbpath/fixtures@0.2.20(transitive)
+ Added@dbpath/types@0.2.20(transitive)
+ Added@dbpath/utils@0.2.20(transitive)
- Removed@dbpath/fixtures@0.2.19(transitive)
- Removed@dbpath/types@0.2.19(transitive)
- Removed@dbpath/utils@0.2.19(transitive)
Updated@dbpath/fixtures@0.2.20
Updated@dbpath/types@0.2.20
Updated@dbpath/utils@0.2.20