Comparing version 1.0.30 to 1.0.31
@@ -138,4 +138,3 @@ "use strict"; | ||
const query = value; | ||
const has_filter = '$where' in value || '$having' in value; | ||
const is_root = path.length === 0; | ||
const has_filter = value.$where || value.$having; | ||
const child_paths = Object.keys(value).map(child_key => { | ||
@@ -149,4 +148,8 @@ if (exports.is_subquery(value[child_key])) { | ||
} | ||
// if this has a $where, or its the root, then all the child paths go to a new tier. Otherwise, the child paths are appended on to the last tier | ||
if (has_filter || is_root) { | ||
const is_root = path.length === 0; // this is to start off the query plan (cant append if there is nothing there) | ||
// entities directly under the root need to ge after because all entitiesneed at least one ancestor which is already queried | ||
// so we can search for those ancestor ids. This ensures that at least the root will have already been searched. | ||
const is_root_child = path.length === 1; | ||
// if this has a $where, or its the root/root child, then all the child paths go to a new tier. Otherwise, the child paths are appended on to the last tier | ||
if (has_filter || is_root || is_root_child) { | ||
query_plan.push(child_paths); | ||
@@ -333,3 +336,3 @@ } | ||
var _a; | ||
if (typeof value === 'object' && '$any' in value) { | ||
if (typeof value === 'object' && value.$any) { | ||
const [any_path, subquery] = value.$any; | ||
@@ -381,3 +384,3 @@ const previous_entities = path.flatMap((path_el, i) => { | ||
const subquery = helpers_1.deep_get(subpath, query); | ||
if ('$where' in subquery || '$having' in subquery) { | ||
if (subquery.$where || subquery.$having) { | ||
return i; | ||
@@ -384,0 +387,0 @@ } |
@@ -81,3 +81,3 @@ "use strict"; | ||
}); | ||
mocha_1.describe('get_query_plan', () => { | ||
mocha_1.describe(query_1.get_query_plan.name, () => { | ||
mocha_1.test('splits by $where clause and $having', () => { | ||
@@ -103,3 +103,4 @@ const query = { | ||
const goal = [ | ||
[['vendors'], ['vendors', 'products']], | ||
[['vendors']], | ||
[['vendors', 'products']], | ||
[ | ||
@@ -109,3 +110,3 @@ ['vendors', 'products', 'vins'], | ||
['vendors', 'products', 'images', 'image_urls'] | ||
] // then this will be queried | ||
] // these are queried concurrently | ||
]; | ||
@@ -124,3 +125,2 @@ chai_1.expect(result).to.deep.equal(goal); | ||
const result = query_1.get_query_plan(query); | ||
// the split happens at variants because it has a where clause | ||
const goal = [[['vendors'], ['products']]]; | ||
@@ -137,3 +137,2 @@ chai_1.expect(result).to.deep.equal(goal); | ||
const result = query_1.get_query_plan(query); | ||
// the split happens at variants because it has a where clause | ||
const goal = [[['my_products']]]; | ||
@@ -430,2 +429,35 @@ chai_1.expect(result).to.deep.equal(goal); | ||
}); | ||
mocha_1.test('ignores undefined where/having clauses', () => { | ||
const query = { | ||
products: { | ||
images: { | ||
$where: undefined, | ||
$having: undefined, | ||
image_urls: {} | ||
} | ||
} | ||
}; | ||
const previous_results = [ | ||
[['products'], [{ id: 1 }, { id: 2 }]], | ||
[['products', 'images'], [{ id: 3 }]] | ||
]; | ||
const json_sql = query_1.query_to_json_sql(query, ['products', 'images', 'image_urls'], previous_results, orma_schema); | ||
const goal = { | ||
$select: ['image_id'], | ||
$from: 'image_urls', | ||
$where: { | ||
$in: [ | ||
'image_id', | ||
{ | ||
$select: ['id'], | ||
$from: 'images', | ||
$where: { | ||
$in: ['product_id', [1, 2]] | ||
} | ||
} | ||
] | ||
} | ||
}; | ||
chai_1.expect(json_sql).to.deep.equal(goal); | ||
}); | ||
mocha_1.test("respects 'from' clause", () => { | ||
@@ -464,11 +496,124 @@ const query = { | ||
chai_1.expect(result).to.deep.equal({ | ||
products: [{ | ||
products: [ | ||
{ | ||
vendor_id: 1, | ||
vendors: [{ | ||
vendors: [ | ||
{ | ||
id: 1 | ||
}] | ||
}] | ||
} | ||
] | ||
} | ||
] | ||
}); | ||
}); | ||
}); | ||
mocha_1.describe.skip('dev', () => { | ||
mocha_1.test('dev', async () => { | ||
const query = { | ||
calls: { | ||
resource_id: true, | ||
call_has_units: { | ||
id: true | ||
} | ||
} | ||
}; | ||
const orma_schema = { | ||
call_has_units: { | ||
$comment: '', | ||
call_id: { | ||
data_type: 'number', | ||
required: true, | ||
indexed: true, | ||
character_count: 10, | ||
references: { calls: { id: {} } } | ||
}, | ||
created_at: { data_type: 'date', required: true, default: 'CURRENT_TIMESTAMP' }, | ||
id: { | ||
data_type: 'number', | ||
required: true, | ||
indexed: true, | ||
unique: true, | ||
primary_key: true, | ||
character_count: 10 | ||
}, | ||
resource_id: { | ||
data_type: 'string', | ||
required: true, | ||
indexed: true, | ||
unique: true, | ||
character_count: 20 | ||
}, | ||
unit_id: { | ||
data_type: 'number', | ||
required: true, | ||
indexed: true, | ||
character_count: 10, | ||
references: { units: { id: {} } } | ||
}, | ||
updated_at: { data_type: 'date', required: true, default: 'CURRENT_TIMESTAMP' } | ||
}, | ||
calls: { | ||
$comment: '', | ||
address: { data_type: 'string', character_count: 250 }, | ||
age: { data_type: 'number', character_count: 10, default: '0' }, | ||
bus_arrived_at: { data_type: 'date' }, | ||
bus_number: { data_type: 'number', character_count: 10 }, | ||
complaint: { data_type: 'string', character_count: 2000 }, | ||
cpr_started: { data_type: 'boolean', character_count: 3 }, | ||
created_at: { data_type: 'date', required: true, default: 'CURRENT_TIMESTAMP' }, | ||
first_name: { data_type: 'string', character_count: 100 }, | ||
gender: { data_type: 'string', character_count: 10 }, | ||
id: { | ||
data_type: 'number', | ||
required: true, | ||
indexed: true, | ||
unique: true, | ||
primary_key: true, | ||
character_count: 10 | ||
}, | ||
last_name: { data_type: 'string', character_count: 100 }, | ||
resource_id: { | ||
data_type: 'string', | ||
required: true, | ||
indexed: true, | ||
unique: true, | ||
character_count: 45 | ||
}, | ||
responsiveness: { data_type: 'string', character_count: 45 }, | ||
summary: { data_type: 'string', character_count: 2000 }, | ||
ten_nine: { data_type: 'string', character_count: 45 }, | ||
updated_at: { data_type: 'date', required: true, default: 'CURRENT_TIMESTAMP' } | ||
}, | ||
units: { | ||
$comment: '', | ||
created_at: { data_type: 'date', required: true, default: 'CURRENT_TIMESTAMP' }, | ||
first_name: { data_type: 'string', character_count: 100 }, | ||
id: { | ||
data_type: 'number', | ||
required: true, | ||
indexed: true, | ||
unique: true, | ||
primary_key: true, | ||
character_count: 10 | ||
}, | ||
last_name: { data_type: 'string', character_count: 100 }, | ||
phone: { data_type: 'string', character_count: 50 }, | ||
resource_id: { | ||
data_type: 'string', | ||
required: true, | ||
indexed: true, | ||
unique: true, | ||
character_count: 45 | ||
}, | ||
updated_at: { data_type: 'date', required: true, default: 'CURRENT_TIMESTAMP' } | ||
} | ||
}; | ||
var actual_query = ''; | ||
const test = await query_1.orma_query(query, orma_schema, sql_strings => { | ||
actual_query = sql_strings[0]; | ||
return Promise.resolve([]); | ||
}); | ||
chai_1.expect(actual_query).to.deep.equal('SELECT id FROM calls'); | ||
}); | ||
}); | ||
}); | ||
@@ -475,0 +620,0 @@ /* |
{ | ||
"name": "orma", | ||
"version": "1.0.30", | ||
"version": "1.0.31", | ||
"description": "A declarative relational syncronous orm", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
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
221615
5343