|
@@ -203,9 +203,23 @@ public int main(string[] args) {
|
|
|
// ProjectionBuilder Tests
|
|
// ProjectionBuilder Tests
|
|
|
// ========================================
|
|
// ========================================
|
|
|
|
|
|
|
|
-OrmSession setup_builder_test_session() throws SqlError, ProjectionError {
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * Test context that holds both session and registry for tests that need to register projections.
|
|
|
|
|
+ */
|
|
|
|
|
+public class ProjectionTestContext : Object {
|
|
|
|
|
+ public OrmSession session;
|
|
|
|
|
+ public TypeRegistry registry;
|
|
|
|
|
+
|
|
|
|
|
+ public ProjectionTestContext(OrmSession session, TypeRegistry registry) {
|
|
|
|
|
+ this.session = session;
|
|
|
|
|
+ this.registry = registry;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+ProjectionTestContext setup_builder_test_context() throws SqlError, ProjectionError {
|
|
|
var conn = ConnectionFactory.create_and_open("sqlite::memory:");
|
|
var conn = ConnectionFactory.create_and_open("sqlite::memory:");
|
|
|
- var session = new OrmSession(conn, new SqliteDialect());
|
|
|
|
|
|
|
+ var dialect = new SqliteDialect();
|
|
|
|
|
+ var registry = new TypeRegistry();
|
|
|
|
|
|
|
|
// Create tables
|
|
// Create tables
|
|
|
conn.execute("""
|
|
conn.execute("""
|
|
@@ -226,35 +240,39 @@ OrmSession setup_builder_test_session() throws SqlError, ProjectionError {
|
|
|
)
|
|
)
|
|
|
""");
|
|
""");
|
|
|
|
|
|
|
|
- // Register entities
|
|
|
|
|
- session.register_with_schema<ProjTestUser>("users", b => {
|
|
|
|
|
|
|
+ // Register entities on registry
|
|
|
|
|
+ registry.register_entity<ProjTestUser>(EntityMapper.build_for<ProjTestUser>(b => {
|
|
|
|
|
+ b.table("users");
|
|
|
b.column<int64?>("id", u => u.id, (u, v) => u.id = v);
|
|
b.column<int64?>("id", u => u.id, (u, v) => u.id = v);
|
|
|
b.column<string>("name", u => u.name, (u, v) => u.name = v);
|
|
b.column<string>("name", u => u.name, (u, v) => u.name = v);
|
|
|
b.column<string>("email", u => u.email, (u, v) => u.email = v);
|
|
b.column<string>("email", u => u.email, (u, v) => u.email = v);
|
|
|
b.column<int64?>("age", u => u.age, (u, v) => u.age = v);
|
|
b.column<int64?>("age", u => u.age, (u, v) => u.age = v);
|
|
|
- });
|
|
|
|
|
|
|
+ }));
|
|
|
|
|
|
|
|
- session.register_with_schema<ProjTestOrder>("orders", b => {
|
|
|
|
|
|
|
+ registry.register_entity<ProjTestOrder>(EntityMapper.build_for<ProjTestOrder>(b => {
|
|
|
|
|
+ b.table("orders");
|
|
|
b.column<int64?>("id", o => o.id, (o, v) => o.id = v);
|
|
b.column<int64?>("id", o => o.id, (o, v) => o.id = v);
|
|
|
b.column<int64?>("user_id", o => o.user_id, (o, v) => o.user_id = v);
|
|
b.column<int64?>("user_id", o => o.user_id, (o, v) => o.user_id = v);
|
|
|
b.column<double?>("total", o => o.total, (o, v) => o.total = v);
|
|
b.column<double?>("total", o => o.total, (o, v) => o.total = v);
|
|
|
b.column<string>("status", o => o.status, (o, v) => o.status = v);
|
|
b.column<string>("status", o => o.status, (o, v) => o.status = v);
|
|
|
- });
|
|
|
|
|
|
|
+ }));
|
|
|
|
|
|
|
|
- return session;
|
|
|
|
|
|
|
+ var session = new OrmSession(conn, registry, dialect);
|
|
|
|
|
+ return new ProjectionTestContext(session, registry);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void test_projection_builder_source() throws Error {
|
|
void test_projection_builder_source() throws Error {
|
|
|
print("Test: ProjectionBuilder source... ");
|
|
print("Test: ProjectionBuilder source... ");
|
|
|
- var session = setup_builder_test_session();
|
|
|
|
|
|
|
+ var ctx = setup_builder_test_context();
|
|
|
|
|
|
|
|
- session.register_projection<SimpleUserProjection>(p => p
|
|
|
|
|
|
|
+ ctx.registry.register_projection<SimpleUserProjection>(new ProjectionBuilder<SimpleUserProjection>(ctx.registry)
|
|
|
.source<ProjTestUser>("u")
|
|
.source<ProjTestUser>("u")
|
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
|
.select<string>("user_name", "u.name", (x, v) => x.user_name = v)
|
|
.select<string>("user_name", "u.name", (x, v) => x.user_name = v)
|
|
|
|
|
+ .build()
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- var definition = session.get_projection_definition<SimpleUserProjection>();
|
|
|
|
|
|
|
+ var definition = ctx.session.get_projection_definition<SimpleUserProjection>();
|
|
|
assert(definition != null);
|
|
assert(definition != null);
|
|
|
assert(definition.source != null);
|
|
assert(definition.source != null);
|
|
|
assert(definition.source.variable_name == "u");
|
|
assert(definition.source.variable_name == "u");
|
|
@@ -266,16 +284,17 @@ void test_projection_builder_source() throws Error {
|
|
|
|
|
|
|
|
void test_projection_builder_join() throws Error {
|
|
void test_projection_builder_join() throws Error {
|
|
|
print("Test: ProjectionBuilder join... ");
|
|
print("Test: ProjectionBuilder join... ");
|
|
|
- var session = setup_builder_test_session();
|
|
|
|
|
|
|
+ var ctx = setup_builder_test_context();
|
|
|
|
|
|
|
|
- session.register_projection<UserOrderDetail>(p => p
|
|
|
|
|
|
|
+ ctx.registry.register_projection<UserOrderDetail>(new ProjectionBuilder<UserOrderDetail>(ctx.registry)
|
|
|
.source<ProjTestUser>("u")
|
|
.source<ProjTestUser>("u")
|
|
|
.join<ProjTestOrder>("o", "u.id == o.user_id")
|
|
.join<ProjTestOrder>("o", "u.id == o.user_id")
|
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
|
.select<int64?>("order_id", "o.id", (x, v) => x.order_id = v)
|
|
.select<int64?>("order_id", "o.id", (x, v) => x.order_id = v)
|
|
|
|
|
+ .build()
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- var definition = session.get_projection_definition<UserOrderDetail>();
|
|
|
|
|
|
|
+ var definition = ctx.session.get_projection_definition<UserOrderDetail>();
|
|
|
assert(definition != null);
|
|
assert(definition != null);
|
|
|
assert(definition.joins.length == 1);
|
|
assert(definition.joins.length == 1);
|
|
|
assert(definition.joins.get(0).variable_name == "o");
|
|
assert(definition.joins.get(0).variable_name == "o");
|
|
@@ -287,15 +306,16 @@ void test_projection_builder_join() throws Error {
|
|
|
|
|
|
|
|
void test_projection_builder_select() throws Error {
|
|
void test_projection_builder_select() throws Error {
|
|
|
print("Test: ProjectionBuilder select... ");
|
|
print("Test: ProjectionBuilder select... ");
|
|
|
- var session = setup_builder_test_session();
|
|
|
|
|
|
|
+ var ctx = setup_builder_test_context();
|
|
|
|
|
|
|
|
- session.register_projection<SimpleUserProjection>(p => p
|
|
|
|
|
|
|
+ ctx.registry.register_projection<SimpleUserProjection>(new ProjectionBuilder<SimpleUserProjection>(ctx.registry)
|
|
|
.source<ProjTestUser>("u")
|
|
.source<ProjTestUser>("u")
|
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
|
.select<string>("user_name", "u.name", (x, v) => x.user_name = v)
|
|
.select<string>("user_name", "u.name", (x, v) => x.user_name = v)
|
|
|
|
|
+ .build()
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- var definition = session.get_projection_definition<SimpleUserProjection>();
|
|
|
|
|
|
|
+ var definition = ctx.session.get_projection_definition<SimpleUserProjection>();
|
|
|
assert(definition != null);
|
|
assert(definition != null);
|
|
|
assert(definition.selections.length == 2);
|
|
assert(definition.selections.length == 2);
|
|
|
assert(definition.selections.get(0).friendly_name == "user_id");
|
|
assert(definition.selections.get(0).friendly_name == "user_id");
|
|
@@ -306,17 +326,18 @@ void test_projection_builder_select() throws Error {
|
|
|
|
|
|
|
|
void test_projection_builder_group_by() throws Error {
|
|
void test_projection_builder_group_by() throws Error {
|
|
|
print("Test: ProjectionBuilder group_by... ");
|
|
print("Test: ProjectionBuilder group_by... ");
|
|
|
- var session = setup_builder_test_session();
|
|
|
|
|
|
|
+ var ctx = setup_builder_test_context();
|
|
|
|
|
|
|
|
- session.register_projection<UserOrderStats>(p => p
|
|
|
|
|
|
|
+ ctx.registry.register_projection<UserOrderStats>(new ProjectionBuilder<UserOrderStats>(ctx.registry)
|
|
|
.source<ProjTestUser>("u")
|
|
.source<ProjTestUser>("u")
|
|
|
.join<ProjTestOrder>("o", "u.id == o.user_id")
|
|
.join<ProjTestOrder>("o", "u.id == o.user_id")
|
|
|
.group_by("u.id")
|
|
.group_by("u.id")
|
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
|
.select<int64?>("order_count", "COUNT(o.id)", (x, v) => x.order_count = v)
|
|
.select<int64?>("order_count", "COUNT(o.id)", (x, v) => x.order_count = v)
|
|
|
|
|
+ .build()
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- var definition = session.get_projection_definition<UserOrderStats>();
|
|
|
|
|
|
|
+ var definition = ctx.session.get_projection_definition<UserOrderStats>();
|
|
|
assert(definition != null);
|
|
assert(definition != null);
|
|
|
assert(definition.group_by_expressions.length == 1);
|
|
assert(definition.group_by_expressions.length == 1);
|
|
|
assert(definition.group_by_expressions.get(0) == "u.id");
|
|
assert(definition.group_by_expressions.get(0) == "u.id");
|
|
@@ -332,16 +353,17 @@ void test_projection_builder_duplicate_variable() throws Error {
|
|
|
// the happy path works correctly.
|
|
// the happy path works correctly.
|
|
|
|
|
|
|
|
// Verify that using different variable names works
|
|
// Verify that using different variable names works
|
|
|
- var session = setup_builder_test_session();
|
|
|
|
|
|
|
+ var ctx = setup_builder_test_context();
|
|
|
|
|
|
|
|
- session.register_projection<UserOrderDetail>(p => p
|
|
|
|
|
|
|
+ ctx.registry.register_projection<UserOrderDetail>(new ProjectionBuilder<UserOrderDetail>(ctx.registry)
|
|
|
.source<ProjTestUser>("u")
|
|
.source<ProjTestUser>("u")
|
|
|
.join<ProjTestOrder>("o", "u.id == o.user_id") // Different variable "o"
|
|
.join<ProjTestOrder>("o", "u.id == o.user_id") // Different variable "o"
|
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
|
.select<int64?>("order_id", "o.id", (x, v) => x.order_id = v)
|
|
.select<int64?>("order_id", "o.id", (x, v) => x.order_id = v)
|
|
|
|
|
+ .build()
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- var definition = session.get_projection_definition<UserOrderDetail>();
|
|
|
|
|
|
|
+ var definition = ctx.session.get_projection_definition<UserOrderDetail>();
|
|
|
assert(definition != null);
|
|
assert(definition != null);
|
|
|
assert(definition.joins.length == 1);
|
|
assert(definition.joins.length == 1);
|
|
|
|
|
|
|
@@ -356,15 +378,16 @@ void test_projection_builder_duplicate_friendly_name() throws Error {
|
|
|
// the happy path works correctly.
|
|
// the happy path works correctly.
|
|
|
|
|
|
|
|
// Verify that using different friendly names works
|
|
// Verify that using different friendly names works
|
|
|
- var session = setup_builder_test_session();
|
|
|
|
|
|
|
+ var ctx = setup_builder_test_context();
|
|
|
|
|
|
|
|
- session.register_projection<SimpleUserProjection>(p => p
|
|
|
|
|
|
|
+ ctx.registry.register_projection<SimpleUserProjection>(new ProjectionBuilder<SimpleUserProjection>(ctx.registry)
|
|
|
.source<ProjTestUser>("u")
|
|
.source<ProjTestUser>("u")
|
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
|
.select<string>("user_name", "u.name", (x, v) => x.user_name = v) // Different friendly name
|
|
.select<string>("user_name", "u.name", (x, v) => x.user_name = v) // Different friendly name
|
|
|
|
|
+ .build()
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- var definition = session.get_projection_definition<SimpleUserProjection>();
|
|
|
|
|
|
|
+ var definition = ctx.session.get_projection_definition<SimpleUserProjection>();
|
|
|
assert(definition != null);
|
|
assert(definition != null);
|
|
|
assert(definition.selections.length == 2);
|
|
assert(definition.selections.length == 2);
|
|
|
assert(definition.selections.get(0).friendly_name == "user_id");
|
|
assert(definition.selections.get(0).friendly_name == "user_id");
|
|
@@ -504,10 +527,10 @@ void test_aggregate_analyzer_split_all_non_aggregate() throws Error {
|
|
|
// VariableTranslator Tests
|
|
// VariableTranslator Tests
|
|
|
// ========================================
|
|
// ========================================
|
|
|
|
|
|
|
|
-OrmSession setup_translator_session() throws SqlError, ProjectionError {
|
|
|
|
|
- var session = setup_builder_test_session();
|
|
|
|
|
|
|
+ProjectionTestContext setup_translator_context() throws SqlError, ProjectionError {
|
|
|
|
|
+ var ctx = setup_builder_test_context();
|
|
|
|
|
|
|
|
- session.register_projection<UserOrderStats>(p => p
|
|
|
|
|
|
|
+ ctx.registry.register_projection<UserOrderStats>(new ProjectionBuilder<UserOrderStats>(ctx.registry)
|
|
|
.source<ProjTestUser>("u")
|
|
.source<ProjTestUser>("u")
|
|
|
.join<ProjTestOrder>("o", "u.id == o.user_id")
|
|
.join<ProjTestOrder>("o", "u.id == o.user_id")
|
|
|
.group_by("u.id")
|
|
.group_by("u.id")
|
|
@@ -515,15 +538,16 @@ OrmSession setup_translator_session() throws SqlError, ProjectionError {
|
|
|
.select<string>("user_name", "u.name", (x, v) => x.user_name = v)
|
|
.select<string>("user_name", "u.name", (x, v) => x.user_name = v)
|
|
|
.select<int64?>("order_count", "COUNT(o.id)", (x, v) => x.order_count = v)
|
|
.select<int64?>("order_count", "COUNT(o.id)", (x, v) => x.order_count = v)
|
|
|
.select<double?>("total_spent", "SUM(o.total)", (x, v) => x.total_spent = v)
|
|
.select<double?>("total_spent", "SUM(o.total)", (x, v) => x.total_spent = v)
|
|
|
|
|
+ .build()
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- return session;
|
|
|
|
|
|
|
+ return ctx;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void test_variable_translator_assign_aliases() throws Error {
|
|
void test_variable_translator_assign_aliases() throws Error {
|
|
|
print("Test: VariableTranslator assign aliases... ");
|
|
print("Test: VariableTranslator assign aliases... ");
|
|
|
- var session = setup_translator_session();
|
|
|
|
|
- var definition = session.get_projection_definition<UserOrderStats>();
|
|
|
|
|
|
|
+ var ctx = setup_translator_context();
|
|
|
|
|
+ var definition = ctx.session.get_projection_definition<UserOrderStats>();
|
|
|
|
|
|
|
|
var translator = new VariableTranslator(definition);
|
|
var translator = new VariableTranslator(definition);
|
|
|
translator.assign_aliases();
|
|
translator.assign_aliases();
|
|
@@ -543,8 +567,8 @@ void test_variable_translator_assign_aliases() throws Error {
|
|
|
|
|
|
|
|
void test_variable_translator_translate_variable() throws Error {
|
|
void test_variable_translator_translate_variable() throws Error {
|
|
|
print("Test: VariableTranslator translate variable... ");
|
|
print("Test: VariableTranslator translate variable... ");
|
|
|
- var session = setup_translator_session();
|
|
|
|
|
- var definition = session.get_projection_definition<UserOrderStats>();
|
|
|
|
|
|
|
+ var ctx = setup_translator_context();
|
|
|
|
|
+ var definition = ctx.session.get_projection_definition<UserOrderStats>();
|
|
|
|
|
|
|
|
var translator = new VariableTranslator(definition);
|
|
var translator = new VariableTranslator(definition);
|
|
|
translator.assign_aliases();
|
|
translator.assign_aliases();
|
|
@@ -560,8 +584,8 @@ void test_variable_translator_translate_variable() throws Error {
|
|
|
|
|
|
|
|
void test_variable_translator_translate_expression() throws Error {
|
|
void test_variable_translator_translate_expression() throws Error {
|
|
|
print("Test: VariableTranslator translate expression... ");
|
|
print("Test: VariableTranslator translate expression... ");
|
|
|
- var session = setup_translator_session();
|
|
|
|
|
- var definition = session.get_projection_definition<UserOrderStats>();
|
|
|
|
|
|
|
+ var ctx = setup_translator_context();
|
|
|
|
|
+ var definition = ctx.session.get_projection_definition<UserOrderStats>();
|
|
|
|
|
|
|
|
var translator = new VariableTranslator(definition);
|
|
var translator = new VariableTranslator(definition);
|
|
|
translator.assign_aliases();
|
|
translator.assign_aliases();
|
|
@@ -583,8 +607,8 @@ void test_variable_translator_translate_expression() throws Error {
|
|
|
|
|
|
|
|
void test_variable_translator_get_mappings() throws Error {
|
|
void test_variable_translator_get_mappings() throws Error {
|
|
|
print("Test: VariableTranslator get mappings... ");
|
|
print("Test: VariableTranslator get mappings... ");
|
|
|
- var session = setup_translator_session();
|
|
|
|
|
- var definition = session.get_projection_definition<UserOrderStats>();
|
|
|
|
|
|
|
+ var ctx = setup_translator_context();
|
|
|
|
|
+ var definition = ctx.session.get_projection_definition<UserOrderStats>();
|
|
|
|
|
|
|
|
var translator = new VariableTranslator(definition);
|
|
var translator = new VariableTranslator(definition);
|
|
|
translator.assign_aliases();
|
|
translator.assign_aliases();
|
|
@@ -597,8 +621,8 @@ void test_variable_translator_get_mappings() throws Error {
|
|
|
|
|
|
|
|
void test_variable_translator_has_variable() throws Error {
|
|
void test_variable_translator_has_variable() throws Error {
|
|
|
print("Test: VariableTranslator has variable... ");
|
|
print("Test: VariableTranslator has variable... ");
|
|
|
- var session = setup_translator_session();
|
|
|
|
|
- var definition = session.get_projection_definition<UserOrderStats>();
|
|
|
|
|
|
|
+ var ctx = setup_translator_context();
|
|
|
|
|
+ var definition = ctx.session.get_projection_definition<UserOrderStats>();
|
|
|
|
|
|
|
|
var translator = new VariableTranslator(definition);
|
|
var translator = new VariableTranslator(definition);
|
|
|
|
|
|
|
@@ -615,8 +639,8 @@ void test_variable_translator_has_variable() throws Error {
|
|
|
|
|
|
|
|
void test_friendly_name_resolver_is_friendly_name() throws Error {
|
|
void test_friendly_name_resolver_is_friendly_name() throws Error {
|
|
|
print("Test: FriendlyNameResolver is_friendly_name... ");
|
|
print("Test: FriendlyNameResolver is_friendly_name... ");
|
|
|
- var session = setup_translator_session();
|
|
|
|
|
- var definition = session.get_projection_definition<UserOrderStats>();
|
|
|
|
|
|
|
+ var ctx = setup_translator_context();
|
|
|
|
|
+ var definition = ctx.session.get_projection_definition<UserOrderStats>();
|
|
|
|
|
|
|
|
var resolver = new FriendlyNameResolver(definition);
|
|
var resolver = new FriendlyNameResolver(definition);
|
|
|
|
|
|
|
@@ -631,8 +655,8 @@ void test_friendly_name_resolver_is_friendly_name() throws Error {
|
|
|
|
|
|
|
|
void test_friendly_name_resolver_resolve_to_expression() throws Error {
|
|
void test_friendly_name_resolver_resolve_to_expression() throws Error {
|
|
|
print("Test: FriendlyNameResolver resolve to expression... ");
|
|
print("Test: FriendlyNameResolver resolve to expression... ");
|
|
|
- var session = setup_translator_session();
|
|
|
|
|
- var definition = session.get_projection_definition<UserOrderStats>();
|
|
|
|
|
|
|
+ var ctx = setup_translator_context();
|
|
|
|
|
+ var definition = ctx.session.get_projection_definition<UserOrderStats>();
|
|
|
|
|
|
|
|
var resolver = new FriendlyNameResolver(definition);
|
|
var resolver = new FriendlyNameResolver(definition);
|
|
|
|
|
|
|
@@ -652,8 +676,8 @@ void test_friendly_name_resolver_resolve_to_expression() throws Error {
|
|
|
|
|
|
|
|
void test_friendly_name_resolver_get_all_names() throws Error {
|
|
void test_friendly_name_resolver_get_all_names() throws Error {
|
|
|
print("Test: FriendlyNameResolver get all names... ");
|
|
print("Test: FriendlyNameResolver get all names... ");
|
|
|
- var session = setup_translator_session();
|
|
|
|
|
- var definition = session.get_projection_definition<UserOrderStats>();
|
|
|
|
|
|
|
+ var ctx = setup_translator_context();
|
|
|
|
|
+ var definition = ctx.session.get_projection_definition<UserOrderStats>();
|
|
|
|
|
|
|
|
var resolver = new FriendlyNameResolver(definition);
|
|
var resolver = new FriendlyNameResolver(definition);
|
|
|
|
|
|
|
@@ -665,8 +689,8 @@ void test_friendly_name_resolver_get_all_names() throws Error {
|
|
|
|
|
|
|
|
void test_friendly_name_resolver_nested_property() throws Error {
|
|
void test_friendly_name_resolver_nested_property() throws Error {
|
|
|
print("Test: FriendlyNameResolver nested property... ");
|
|
print("Test: FriendlyNameResolver nested property... ");
|
|
|
- var session = setup_translator_session();
|
|
|
|
|
- var definition = session.get_projection_definition<UserOrderStats>();
|
|
|
|
|
|
|
+ var ctx = setup_translator_context();
|
|
|
|
|
+ var definition = ctx.session.get_projection_definition<UserOrderStats>();
|
|
|
|
|
|
|
|
var resolver = new FriendlyNameResolver(definition);
|
|
var resolver = new FriendlyNameResolver(definition);
|
|
|
|
|
|
|
@@ -688,15 +712,16 @@ void test_friendly_name_resolver_nested_property() throws Error {
|
|
|
|
|
|
|
|
void test_projection_sql_builder_simple() throws Error {
|
|
void test_projection_sql_builder_simple() throws Error {
|
|
|
print("Test: ProjectionSqlBuilder simple... ");
|
|
print("Test: ProjectionSqlBuilder simple... ");
|
|
|
- var session = setup_builder_test_session();
|
|
|
|
|
|
|
+ var ctx = setup_builder_test_context();
|
|
|
|
|
|
|
|
- session.register_projection<SimpleUserProjection>(p => p
|
|
|
|
|
|
|
+ ctx.registry.register_projection<SimpleUserProjection>(new ProjectionBuilder<SimpleUserProjection>(ctx.registry)
|
|
|
.source<ProjTestUser>("u")
|
|
.source<ProjTestUser>("u")
|
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
|
.select<string>("user_name", "u.name", (x, v) => x.user_name = v)
|
|
.select<string>("user_name", "u.name", (x, v) => x.user_name = v)
|
|
|
|
|
+ .build()
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- var definition = session.get_projection_definition<SimpleUserProjection>();
|
|
|
|
|
|
|
+ var definition = ctx.session.get_projection_definition<SimpleUserProjection>();
|
|
|
var sql_builder = new ProjectionSqlBuilder(definition, new SqliteDialect());
|
|
var sql_builder = new ProjectionSqlBuilder(definition, new SqliteDialect());
|
|
|
|
|
|
|
|
var sql = sql_builder.build();
|
|
var sql = sql_builder.build();
|
|
@@ -710,16 +735,17 @@ void test_projection_sql_builder_simple() throws Error {
|
|
|
|
|
|
|
|
void test_projection_sql_builder_with_join() throws Error {
|
|
void test_projection_sql_builder_with_join() throws Error {
|
|
|
print("Test: ProjectionSqlBuilder with join... ");
|
|
print("Test: ProjectionSqlBuilder with join... ");
|
|
|
- var session = setup_builder_test_session();
|
|
|
|
|
|
|
+ var ctx = setup_builder_test_context();
|
|
|
|
|
|
|
|
- session.register_projection<UserOrderDetail>(p => p
|
|
|
|
|
|
|
+ ctx.registry.register_projection<UserOrderDetail>(new ProjectionBuilder<UserOrderDetail>(ctx.registry)
|
|
|
.source<ProjTestUser>("u")
|
|
.source<ProjTestUser>("u")
|
|
|
.join<ProjTestOrder>("o", "u.id == o.user_id")
|
|
.join<ProjTestOrder>("o", "u.id == o.user_id")
|
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
|
.select<int64?>("order_id", "o.id", (x, v) => x.order_id = v)
|
|
.select<int64?>("order_id", "o.id", (x, v) => x.order_id = v)
|
|
|
|
|
+ .build()
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- var definition = session.get_projection_definition<UserOrderDetail>();
|
|
|
|
|
|
|
+ var definition = ctx.session.get_projection_definition<UserOrderDetail>();
|
|
|
var sql_builder = new ProjectionSqlBuilder(definition, new SqliteDialect());
|
|
var sql_builder = new ProjectionSqlBuilder(definition, new SqliteDialect());
|
|
|
|
|
|
|
|
var sql = sql_builder.build();
|
|
var sql = sql_builder.build();
|
|
@@ -733,17 +759,18 @@ void test_projection_sql_builder_with_join() throws Error {
|
|
|
|
|
|
|
|
void test_projection_sql_builder_with_group_by() throws Error {
|
|
void test_projection_sql_builder_with_group_by() throws Error {
|
|
|
print("Test: ProjectionSqlBuilder with GROUP BY... ");
|
|
print("Test: ProjectionSqlBuilder with GROUP BY... ");
|
|
|
- var session = setup_builder_test_session();
|
|
|
|
|
|
|
+ var ctx = setup_builder_test_context();
|
|
|
|
|
|
|
|
- session.register_projection<UserOrderStats>(p => p
|
|
|
|
|
|
|
+ ctx.registry.register_projection<UserOrderStats>(new ProjectionBuilder<UserOrderStats>(ctx.registry)
|
|
|
.source<ProjTestUser>("u")
|
|
.source<ProjTestUser>("u")
|
|
|
.join<ProjTestOrder>("o", "u.id == o.user_id")
|
|
.join<ProjTestOrder>("o", "u.id == o.user_id")
|
|
|
.group_by("u.id")
|
|
.group_by("u.id")
|
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
|
.select<int64?>("order_count", "COUNT(o.id)", (x, v) => x.order_count = v)
|
|
.select<int64?>("order_count", "COUNT(o.id)", (x, v) => x.order_count = v)
|
|
|
|
|
+ .build()
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- var definition = session.get_projection_definition<UserOrderStats>();
|
|
|
|
|
|
|
+ var definition = ctx.session.get_projection_definition<UserOrderStats>();
|
|
|
var sql_builder = new ProjectionSqlBuilder(definition, new SqliteDialect());
|
|
var sql_builder = new ProjectionSqlBuilder(definition, new SqliteDialect());
|
|
|
|
|
|
|
|
var sql = sql_builder.build();
|
|
var sql = sql_builder.build();
|
|
@@ -755,15 +782,16 @@ void test_projection_sql_builder_with_group_by() throws Error {
|
|
|
|
|
|
|
|
void test_projection_sql_builder_with_where() throws Error {
|
|
void test_projection_sql_builder_with_where() throws Error {
|
|
|
print("Test: ProjectionSqlBuilder with WHERE... ");
|
|
print("Test: ProjectionSqlBuilder with WHERE... ");
|
|
|
- var session = setup_builder_test_session();
|
|
|
|
|
|
|
+ var ctx = setup_builder_test_context();
|
|
|
|
|
|
|
|
- session.register_projection<SimpleUserProjection>(p => p
|
|
|
|
|
|
|
+ ctx.registry.register_projection<SimpleUserProjection>(new ProjectionBuilder<SimpleUserProjection>(ctx.registry)
|
|
|
.source<ProjTestUser>("u")
|
|
.source<ProjTestUser>("u")
|
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
|
.select<string>("user_name", "u.name", (x, v) => x.user_name = v)
|
|
.select<string>("user_name", "u.name", (x, v) => x.user_name = v)
|
|
|
|
|
+ .build()
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- var definition = session.get_projection_definition<SimpleUserProjection>();
|
|
|
|
|
|
|
+ var definition = ctx.session.get_projection_definition<SimpleUserProjection>();
|
|
|
var sql_builder = new ProjectionSqlBuilder(definition, new SqliteDialect());
|
|
var sql_builder = new ProjectionSqlBuilder(definition, new SqliteDialect());
|
|
|
|
|
|
|
|
var sql = sql_builder.build("u.age > 18");
|
|
var sql = sql_builder.build("u.age > 18");
|
|
@@ -775,17 +803,18 @@ void test_projection_sql_builder_with_where() throws Error {
|
|
|
|
|
|
|
|
void test_projection_sql_builder_with_having() throws Error {
|
|
void test_projection_sql_builder_with_having() throws Error {
|
|
|
print("Test: ProjectionSqlBuilder with HAVING... ");
|
|
print("Test: ProjectionSqlBuilder with HAVING... ");
|
|
|
- var session = setup_builder_test_session();
|
|
|
|
|
|
|
+ var ctx = setup_builder_test_context();
|
|
|
|
|
|
|
|
- session.register_projection<UserOrderStats>(p => p
|
|
|
|
|
|
|
+ ctx.registry.register_projection<UserOrderStats>(new ProjectionBuilder<UserOrderStats>(ctx.registry)
|
|
|
.source<ProjTestUser>("u")
|
|
.source<ProjTestUser>("u")
|
|
|
.join<ProjTestOrder>("o", "u.id == o.user_id")
|
|
.join<ProjTestOrder>("o", "u.id == o.user_id")
|
|
|
.group_by("u.id")
|
|
.group_by("u.id")
|
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
|
.select<int64?>("order_count", "COUNT(o.id)", (x, v) => x.order_count = v)
|
|
.select<int64?>("order_count", "COUNT(o.id)", (x, v) => x.order_count = v)
|
|
|
|
|
+ .build()
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- var definition = session.get_projection_definition<UserOrderStats>();
|
|
|
|
|
|
|
+ var definition = ctx.session.get_projection_definition<UserOrderStats>();
|
|
|
var sql_builder = new ProjectionSqlBuilder(definition, new SqliteDialect());
|
|
var sql_builder = new ProjectionSqlBuilder(definition, new SqliteDialect());
|
|
|
|
|
|
|
|
// Use build_with_split for aggregate conditions
|
|
// Use build_with_split for aggregate conditions
|
|
@@ -798,15 +827,16 @@ void test_projection_sql_builder_with_having() throws Error {
|
|
|
|
|
|
|
|
void test_projection_sql_builder_with_order_by() throws Error {
|
|
void test_projection_sql_builder_with_order_by() throws Error {
|
|
|
print("Test: ProjectionSqlBuilder with ORDER BY... ");
|
|
print("Test: ProjectionSqlBuilder with ORDER BY... ");
|
|
|
- var session = setup_builder_test_session();
|
|
|
|
|
|
|
+ var ctx = setup_builder_test_context();
|
|
|
|
|
|
|
|
- session.register_projection<SimpleUserProjection>(p => p
|
|
|
|
|
|
|
+ ctx.registry.register_projection<SimpleUserProjection>(new ProjectionBuilder<SimpleUserProjection>(ctx.registry)
|
|
|
.source<ProjTestUser>("u")
|
|
.source<ProjTestUser>("u")
|
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
|
.select<string>("user_name", "u.name", (x, v) => x.user_name = v)
|
|
.select<string>("user_name", "u.name", (x, v) => x.user_name = v)
|
|
|
|
|
+ .build()
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- var definition = session.get_projection_definition<SimpleUserProjection>();
|
|
|
|
|
|
|
+ var definition = ctx.session.get_projection_definition<SimpleUserProjection>();
|
|
|
var sql_builder = new ProjectionSqlBuilder(definition, new SqliteDialect());
|
|
var sql_builder = new ProjectionSqlBuilder(definition, new SqliteDialect());
|
|
|
|
|
|
|
|
var order_by = new Vector<OrderByClause>();
|
|
var order_by = new Vector<OrderByClause>();
|
|
@@ -822,15 +852,16 @@ void test_projection_sql_builder_with_order_by() throws Error {
|
|
|
|
|
|
|
|
void test_projection_sql_builder_with_limit_offset() throws Error {
|
|
void test_projection_sql_builder_with_limit_offset() throws Error {
|
|
|
print("Test: ProjectionSqlBuilder with LIMIT/OFFSET... ");
|
|
print("Test: ProjectionSqlBuilder with LIMIT/OFFSET... ");
|
|
|
- var session = setup_builder_test_session();
|
|
|
|
|
|
|
+ var ctx = setup_builder_test_context();
|
|
|
|
|
|
|
|
- session.register_projection<SimpleUserProjection>(p => p
|
|
|
|
|
|
|
+ ctx.registry.register_projection<SimpleUserProjection>(new ProjectionBuilder<SimpleUserProjection>(ctx.registry)
|
|
|
.source<ProjTestUser>("u")
|
|
.source<ProjTestUser>("u")
|
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
|
.select<string>("user_name", "u.name", (x, v) => x.user_name = v)
|
|
.select<string>("user_name", "u.name", (x, v) => x.user_name = v)
|
|
|
|
|
+ .build()
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- var definition = session.get_projection_definition<SimpleUserProjection>();
|
|
|
|
|
|
|
+ var definition = ctx.session.get_projection_definition<SimpleUserProjection>();
|
|
|
var sql_builder = new ProjectionSqlBuilder(definition, new SqliteDialect());
|
|
var sql_builder = new ProjectionSqlBuilder(definition, new SqliteDialect());
|
|
|
|
|
|
|
|
var sql = sql_builder.build(null, null, 10, 5);
|
|
var sql = sql_builder.build(null, null, 10, 5);
|
|
@@ -845,17 +876,18 @@ void test_projection_sql_builder_with_limit_offset() throws Error {
|
|
|
|
|
|
|
|
void test_projection_sql_builder_subquery_detection() throws Error {
|
|
void test_projection_sql_builder_subquery_detection() throws Error {
|
|
|
print("Test: ProjectionSqlBuilder subquery detection... ");
|
|
print("Test: ProjectionSqlBuilder subquery detection... ");
|
|
|
- var session = setup_builder_test_session();
|
|
|
|
|
|
|
+ var ctx = setup_builder_test_context();
|
|
|
|
|
|
|
|
- session.register_projection<UserOrderStats>(p => p
|
|
|
|
|
|
|
+ ctx.registry.register_projection<UserOrderStats>(new ProjectionBuilder<UserOrderStats>(ctx.registry)
|
|
|
.source<ProjTestUser>("u")
|
|
.source<ProjTestUser>("u")
|
|
|
.join<ProjTestOrder>("o", "u.id == o.user_id")
|
|
.join<ProjTestOrder>("o", "u.id == o.user_id")
|
|
|
.group_by("u.id")
|
|
.group_by("u.id")
|
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
|
.select<int64?>("order_count", "COUNT(o.id)", (x, v) => x.order_count = v)
|
|
.select<int64?>("order_count", "COUNT(o.id)", (x, v) => x.order_count = v)
|
|
|
|
|
+ .build()
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- var definition = session.get_projection_definition<UserOrderStats>();
|
|
|
|
|
|
|
+ var definition = ctx.session.get_projection_definition<UserOrderStats>();
|
|
|
var sql_builder = new ProjectionSqlBuilder(definition, new SqliteDialect());
|
|
var sql_builder = new ProjectionSqlBuilder(definition, new SqliteDialect());
|
|
|
|
|
|
|
|
// Mixed OR should trigger subquery
|
|
// Mixed OR should trigger subquery
|
|
@@ -870,9 +902,10 @@ void test_projection_sql_builder_subquery_detection() throws Error {
|
|
|
// Integration Tests
|
|
// Integration Tests
|
|
|
// ========================================
|
|
// ========================================
|
|
|
|
|
|
|
|
-OrmSession setup_integration_session() throws SqlError, ProjectionError {
|
|
|
|
|
|
|
+ProjectionTestContext setup_integration_context() throws SqlError, ProjectionError {
|
|
|
var conn = ConnectionFactory.create_and_open("sqlite::memory:");
|
|
var conn = ConnectionFactory.create_and_open("sqlite::memory:");
|
|
|
- var session = new OrmSession(conn, new SqliteDialect());
|
|
|
|
|
|
|
+ var dialect = new SqliteDialect();
|
|
|
|
|
+ var registry = new TypeRegistry();
|
|
|
|
|
|
|
|
// Create tables
|
|
// Create tables
|
|
|
conn.execute("""
|
|
conn.execute("""
|
|
@@ -911,34 +944,40 @@ OrmSession setup_integration_session() throws SqlError, ProjectionError {
|
|
|
)
|
|
)
|
|
|
""");
|
|
""");
|
|
|
|
|
|
|
|
- // Register entities
|
|
|
|
|
- session.register_with_schema<ProjTestUser>("users", b => {
|
|
|
|
|
|
|
+ // Register entities on registry
|
|
|
|
|
+ registry.register_entity<ProjTestUser>(EntityMapper.build_for<ProjTestUser>(b => {
|
|
|
|
|
+ b.table("users");
|
|
|
b.column<int64?>("id", u => u.id, (u, v) => u.id = v);
|
|
b.column<int64?>("id", u => u.id, (u, v) => u.id = v);
|
|
|
b.column<string>("name", u => u.name, (u, v) => u.name = v);
|
|
b.column<string>("name", u => u.name, (u, v) => u.name = v);
|
|
|
b.column<string>("email", u => u.email, (u, v) => u.email = v);
|
|
b.column<string>("email", u => u.email, (u, v) => u.email = v);
|
|
|
b.column<int64?>("age", u => u.age, (u, v) => u.age = v);
|
|
b.column<int64?>("age", u => u.age, (u, v) => u.age = v);
|
|
|
- });
|
|
|
|
|
|
|
+ }));
|
|
|
|
|
|
|
|
- session.register_with_schema<ProjTestOrder>("orders", b => {
|
|
|
|
|
|
|
+ registry.register_entity<ProjTestOrder>(EntityMapper.build_for<ProjTestOrder>(b => {
|
|
|
|
|
+ b.table("orders");
|
|
|
b.column<int64?>("id", o => o.id, (o, v) => o.id = v);
|
|
b.column<int64?>("id", o => o.id, (o, v) => o.id = v);
|
|
|
b.column<int64?>("user_id", o => o.user_id, (o, v) => o.user_id = v);
|
|
b.column<int64?>("user_id", o => o.user_id, (o, v) => o.user_id = v);
|
|
|
b.column<double?>("total", o => o.total, (o, v) => o.total = v);
|
|
b.column<double?>("total", o => o.total, (o, v) => o.total = v);
|
|
|
b.column<string>("status", o => o.status, (o, v) => o.status = v);
|
|
b.column<string>("status", o => o.status, (o, v) => o.status = v);
|
|
|
- });
|
|
|
|
|
|
|
+ }));
|
|
|
|
|
|
|
|
- session.register_with_schema<ProjTestProduct>("products", b => {
|
|
|
|
|
|
|
+ registry.register_entity<ProjTestProduct>(EntityMapper.build_for<ProjTestProduct>(b => {
|
|
|
|
|
+ b.table("products");
|
|
|
b.column<int64?>("id", p => p.id, (p, v) => p.id = v);
|
|
b.column<int64?>("id", p => p.id, (p, v) => p.id = v);
|
|
|
b.column<string>("name", p => p.name, (p, v) => p.name = v);
|
|
b.column<string>("name", p => p.name, (p, v) => p.name = v);
|
|
|
b.column<double?>("price", p => p.price, (p, v) => p.price = v);
|
|
b.column<double?>("price", p => p.price, (p, v) => p.price = v);
|
|
|
- });
|
|
|
|
|
|
|
+ }));
|
|
|
|
|
|
|
|
- session.register_with_schema<ProjTestOrderItem>("order_items", b => {
|
|
|
|
|
|
|
+ registry.register_entity<ProjTestOrderItem>(EntityMapper.build_for<ProjTestOrderItem>(b => {
|
|
|
|
|
+ b.table("order_items");
|
|
|
b.column<int64?>("id", oi => oi.id, (oi, v) => oi.id = v);
|
|
b.column<int64?>("id", oi => oi.id, (oi, v) => oi.id = v);
|
|
|
b.column<int64?>("order_id", oi => oi.order_id, (oi, v) => oi.order_id = v);
|
|
b.column<int64?>("order_id", oi => oi.order_id, (oi, v) => oi.order_id = v);
|
|
|
b.column<int64?>("product_id", oi => oi.product_id, (oi, v) => oi.product_id = v);
|
|
b.column<int64?>("product_id", oi => oi.product_id, (oi, v) => oi.product_id = v);
|
|
|
b.column<int64?>("quantity", oi => oi.quantity, (oi, v) => oi.quantity = v);
|
|
b.column<int64?>("quantity", oi => oi.quantity, (oi, v) => oi.quantity = v);
|
|
|
b.column<double?>("unit_price", oi => oi.unit_price, (oi, v) => oi.unit_price = v);
|
|
b.column<double?>("unit_price", oi => oi.unit_price, (oi, v) => oi.unit_price = v);
|
|
|
- });
|
|
|
|
|
|
|
+ }));
|
|
|
|
|
+
|
|
|
|
|
+ var session = new OrmSession(conn, registry, dialect);
|
|
|
|
|
|
|
|
// Insert test data
|
|
// Insert test data
|
|
|
// Users
|
|
// Users
|
|
@@ -954,20 +993,21 @@ OrmSession setup_integration_session() throws SqlError, ProjectionError {
|
|
|
conn.execute("INSERT INTO orders (user_id, total, status) VALUES (3, 150.0, 'completed')");
|
|
conn.execute("INSERT INTO orders (user_id, total, status) VALUES (3, 150.0, 'completed')");
|
|
|
conn.execute("INSERT INTO orders (user_id, total, status) VALUES (3, 75.0, 'pending')");
|
|
conn.execute("INSERT INTO orders (user_id, total, status) VALUES (3, 75.0, 'pending')");
|
|
|
|
|
|
|
|
- return session;
|
|
|
|
|
|
|
+ return new ProjectionTestContext(session, registry);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void test_projection_registration() throws Error {
|
|
void test_projection_registration() throws Error {
|
|
|
print("Test: Projection registration... ");
|
|
print("Test: Projection registration... ");
|
|
|
- var session = setup_integration_session();
|
|
|
|
|
|
|
+ var ctx = setup_integration_context();
|
|
|
|
|
|
|
|
- session.register_projection<SimpleUserProjection>(p => p
|
|
|
|
|
|
|
+ ctx.registry.register_projection<SimpleUserProjection>(new ProjectionBuilder<SimpleUserProjection>(ctx.registry)
|
|
|
.source<ProjTestUser>("u")
|
|
.source<ProjTestUser>("u")
|
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
|
.select<string>("user_name", "u.name", (x, v) => x.user_name = v)
|
|
.select<string>("user_name", "u.name", (x, v) => x.user_name = v)
|
|
|
|
|
+ .build()
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- var definition = session.get_projection_definition<SimpleUserProjection>();
|
|
|
|
|
|
|
+ var definition = ctx.session.get_projection_definition<SimpleUserProjection>();
|
|
|
assert(definition != null);
|
|
assert(definition != null);
|
|
|
assert(definition.source != null);
|
|
assert(definition.source != null);
|
|
|
assert(definition.selections.length == 2);
|
|
assert(definition.selections.length == 2);
|
|
@@ -977,15 +1017,16 @@ void test_projection_registration() throws Error {
|
|
|
|
|
|
|
|
void test_simple_projection_query() throws Error {
|
|
void test_simple_projection_query() throws Error {
|
|
|
print("Test: Simple projection query... ");
|
|
print("Test: Simple projection query... ");
|
|
|
- var session = setup_integration_session();
|
|
|
|
|
|
|
+ var ctx = setup_integration_context();
|
|
|
|
|
|
|
|
- session.register_projection<SimpleUserProjection>(p => p
|
|
|
|
|
|
|
+ ctx.registry.register_projection<SimpleUserProjection>(new ProjectionBuilder<SimpleUserProjection>(ctx.registry)
|
|
|
.source<ProjTestUser>("u")
|
|
.source<ProjTestUser>("u")
|
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
|
.select<string>("user_name", "u.name", (x, v) => x.user_name = v)
|
|
.select<string>("user_name", "u.name", (x, v) => x.user_name = v)
|
|
|
|
|
+ .build()
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- var query = session.query_projection<SimpleUserProjection>();
|
|
|
|
|
|
|
+ var query = ctx.session.query_projection<SimpleUserProjection>();
|
|
|
string sql = query.to_sql();
|
|
string sql = query.to_sql();
|
|
|
print("\n Generated SQL: %s\n", sql);
|
|
print("\n Generated SQL: %s\n", sql);
|
|
|
|
|
|
|
@@ -1011,15 +1052,16 @@ void test_simple_projection_query() throws Error {
|
|
|
|
|
|
|
|
void test_projection_with_where() throws Error {
|
|
void test_projection_with_where() throws Error {
|
|
|
print("Test: Projection with WHERE... ");
|
|
print("Test: Projection with WHERE... ");
|
|
|
- var session = setup_integration_session();
|
|
|
|
|
|
|
+ var ctx = setup_integration_context();
|
|
|
|
|
|
|
|
- session.register_projection<SimpleUserProjection>(p => p
|
|
|
|
|
|
|
+ ctx.registry.register_projection<SimpleUserProjection>(new ProjectionBuilder<SimpleUserProjection>(ctx.registry)
|
|
|
.source<ProjTestUser>("u")
|
|
.source<ProjTestUser>("u")
|
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
|
.select<string>("user_name", "u.name", (x, v) => x.user_name = v)
|
|
.select<string>("user_name", "u.name", (x, v) => x.user_name = v)
|
|
|
|
|
+ .build()
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- var query = session.query_projection<SimpleUserProjection>()
|
|
|
|
|
|
|
+ var query = ctx.session.query_projection<SimpleUserProjection>()
|
|
|
.where("u.age > 28");
|
|
.where("u.age > 28");
|
|
|
string sql = query.to_sql();
|
|
string sql = query.to_sql();
|
|
|
print("\n Generated SQL: %s\n", sql);
|
|
print("\n Generated SQL: %s\n", sql);
|
|
@@ -1034,15 +1076,16 @@ void test_projection_with_where() throws Error {
|
|
|
|
|
|
|
|
void test_projection_with_order_by() throws Error {
|
|
void test_projection_with_order_by() throws Error {
|
|
|
print("Test: Projection with ORDER BY... ");
|
|
print("Test: Projection with ORDER BY... ");
|
|
|
- var session = setup_integration_session();
|
|
|
|
|
|
|
+ var ctx = setup_integration_context();
|
|
|
|
|
|
|
|
- session.register_projection<SimpleUserProjection>(p => p
|
|
|
|
|
|
|
+ ctx.registry.register_projection<SimpleUserProjection>(new ProjectionBuilder<SimpleUserProjection>(ctx.registry)
|
|
|
.source<ProjTestUser>("u")
|
|
.source<ProjTestUser>("u")
|
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
|
.select<string>("user_name", "u.name", (x, v) => x.user_name = v)
|
|
.select<string>("user_name", "u.name", (x, v) => x.user_name = v)
|
|
|
|
|
+ .build()
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- var results = session.query_projection<SimpleUserProjection>()
|
|
|
|
|
|
|
+ var results = ctx.session.query_projection<SimpleUserProjection>()
|
|
|
.order_by_desc("user_name")
|
|
.order_by_desc("user_name")
|
|
|
.materialise();
|
|
.materialise();
|
|
|
|
|
|
|
@@ -1059,15 +1102,16 @@ void test_projection_with_order_by() throws Error {
|
|
|
|
|
|
|
|
void test_projection_with_limit_offset() throws Error {
|
|
void test_projection_with_limit_offset() throws Error {
|
|
|
print("Test: Projection with LIMIT/OFFSET... ");
|
|
print("Test: Projection with LIMIT/OFFSET... ");
|
|
|
- var session = setup_integration_session();
|
|
|
|
|
|
|
+ var ctx = setup_integration_context();
|
|
|
|
|
|
|
|
- session.register_projection<SimpleUserProjection>(p => p
|
|
|
|
|
|
|
+ ctx.registry.register_projection<SimpleUserProjection>(new ProjectionBuilder<SimpleUserProjection>(ctx.registry)
|
|
|
.source<ProjTestUser>("u")
|
|
.source<ProjTestUser>("u")
|
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
|
.select<string>("user_name", "u.name", (x, v) => x.user_name = v)
|
|
.select<string>("user_name", "u.name", (x, v) => x.user_name = v)
|
|
|
|
|
+ .build()
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- var results = session.query_projection<SimpleUserProjection>()
|
|
|
|
|
|
|
+ var results = ctx.session.query_projection<SimpleUserProjection>()
|
|
|
.order_by("user_id")
|
|
.order_by("user_id")
|
|
|
.limit(2)
|
|
.limit(2)
|
|
|
.offset(1)
|
|
.offset(1)
|
|
@@ -1085,9 +1129,9 @@ void test_projection_with_limit_offset() throws Error {
|
|
|
|
|
|
|
|
void test_projection_with_aggregates() throws Error {
|
|
void test_projection_with_aggregates() throws Error {
|
|
|
print("Test: Projection with aggregates... ");
|
|
print("Test: Projection with aggregates... ");
|
|
|
- var session = setup_integration_session();
|
|
|
|
|
|
|
+ var ctx = setup_integration_context();
|
|
|
|
|
|
|
|
- session.register_projection<UserOrderStats>(p => p
|
|
|
|
|
|
|
+ ctx.registry.register_projection<UserOrderStats>(new ProjectionBuilder<UserOrderStats>(ctx.registry)
|
|
|
.source<ProjTestUser>("u")
|
|
.source<ProjTestUser>("u")
|
|
|
.join<ProjTestOrder>("o", "u.id == o.user_id")
|
|
.join<ProjTestOrder>("o", "u.id == o.user_id")
|
|
|
.group_by("u.id")
|
|
.group_by("u.id")
|
|
@@ -1095,9 +1139,10 @@ void test_projection_with_aggregates() throws Error {
|
|
|
.select<string>("user_name", "u.name", (x, v) => x.user_name = v)
|
|
.select<string>("user_name", "u.name", (x, v) => x.user_name = v)
|
|
|
.select<int64?>("order_count", "COUNT(o.id)", (x, v) => x.order_count = v)
|
|
.select<int64?>("order_count", "COUNT(o.id)", (x, v) => x.order_count = v)
|
|
|
.select<double?>("total_spent", "SUM(o.total)", (x, v) => x.total_spent = v)
|
|
.select<double?>("total_spent", "SUM(o.total)", (x, v) => x.total_spent = v)
|
|
|
|
|
+ .build()
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- var results = session.query_projection<UserOrderStats>()
|
|
|
|
|
|
|
+ var results = ctx.session.query_projection<UserOrderStats>()
|
|
|
.order_by("user_id")
|
|
.order_by("user_id")
|
|
|
.materialise();
|
|
.materialise();
|
|
|
|
|
|
|
@@ -1125,18 +1170,19 @@ void test_projection_with_aggregates() throws Error {
|
|
|
|
|
|
|
|
void test_projection_with_joins() throws Error {
|
|
void test_projection_with_joins() throws Error {
|
|
|
print("Test: Projection with JOINs... ");
|
|
print("Test: Projection with JOINs... ");
|
|
|
- var session = setup_integration_session();
|
|
|
|
|
|
|
+ var ctx = setup_integration_context();
|
|
|
|
|
|
|
|
- session.register_projection<UserOrderDetail>(p => p
|
|
|
|
|
|
|
+ ctx.registry.register_projection<UserOrderDetail>(new ProjectionBuilder<UserOrderDetail>(ctx.registry)
|
|
|
.source<ProjTestUser>("u")
|
|
.source<ProjTestUser>("u")
|
|
|
.join<ProjTestOrder>("o", "u.id == o.user_id")
|
|
.join<ProjTestOrder>("o", "u.id == o.user_id")
|
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
.select<int64?>("user_id", "u.id", (x, v) => x.user_id = v)
|
|
|
.select<string>("user_name", "u.name", (x, v) => x.user_name = v)
|
|
.select<string>("user_name", "u.name", (x, v) => x.user_name = v)
|
|
|
.select<int64?>("order_id", "o.id", (x, v) => x.order_id = v)
|
|
.select<int64?>("order_id", "o.id", (x, v) => x.order_id = v)
|
|
|
.select<double?>("order_total", "o.total", (x, v) => x.order_total = v)
|
|
.select<double?>("order_total", "o.total", (x, v) => x.order_total = v)
|
|
|
|
|
+ .build()
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- var results = session.query_projection<UserOrderDetail>()
|
|
|
|
|
|
|
+ var results = ctx.session.query_projection<UserOrderDetail>()
|
|
|
.order_by("user_id")
|
|
.order_by("user_id")
|
|
|
.materialise();
|
|
.materialise();
|
|
|
|
|
|