开发者

how to design the query for non-sql database

开发者 https://www.devze.com 2022-12-29 15:34 出处:网络
can anyone give some reference for non-sql database query interface design pattern? For sql-based database, the query can be achieved by combining the query token.

can anyone give some reference for non-sql database query interface design pattern?

For sql-based database, the query can be achieved by combining the query token. but for non-sql, how to design the query, given that the query could be 开发者_高级运维very complex.

EDIT:

I am using db4o to store some objects, I may need to query according to a certain Id, time range, or the combination of them.

How to design the query method?

public IEnumerable<Foo> GetFoos(int id);
public IEnumerable<Foo> GetFoos(int id, TimeRange range);

To build a lot of overloads seem stupid, what if a new query is needed?


In C#, it's definitely best to use Linq. Native Queries often fail to optimize, which will lead db4o to hydrate all objects and actually call the lambda expression on the instantiated object. That is nothing but an automated fallback to linq-to-objects and it's damn slow in comparison. Merely hydrating 60k of our typical objects takes multiple seconds.

Hint: A breakpoint on the lambda expression must never be invoked.

Even when using Db4oTool.exe to optimize native queries as a post-build step, even simple queries lead to problems when using properties or auto-properties in domain objects.

The linq provider always gave the best results for me. It has the most concise syntax and it's optimizations work. Also the linq provider is very complete, only it might fall back to linq-to-objects more often than you expect.

Also, it's important for the linq provider to have certain dlls in the project folder. Which these are depends on the version a bit. If you are using builds >= 14204, make sure Mono.Reflection.dll is in your app folder.

For older versions, all of the following must be present:

Db4obects.Db4o.Instrumentation.dll
Db4objects.Db4o.NativeQueries.dll
Mono.Cecil.dll
Cecil.FlowAnalysis.dll

Note that for native queries these are still required even in newer builds.


It looks like db4o uses its own queries, which Versant calls Native Queries (note: there's a separate syntax for .Net and Java native queries). Something like:

IObjectContainer container = Database();
container.Query(delegate(Foo foo) {
    return foo.id == id;
});

container.Query(delegate(Foo foo) {
        return foo.id == id;
    },
    delegate(Foo foo) {
        return range.IsIn(foo.time);
    });
0

精彩评论

暂无评论...
验证码 换一张
取 消