ColdFusion 外部查询的查询
我使用 Adobe ColdFusion 的体验,尽管仍然有些有限,但绝对是快乐和愉快的。
在我能说的关于 ColdFusion 的所有优点中,有一项功能完全让我震惊。 它可能既不是很有效,也不是在生产中有用,但无论如何,我正在谈论所谓的“查询的查询”功能,或者 cfquery 的 dbtype="query" 属性。 它允许您针对任意数据集运行 SQL 语句,而不仅仅是数据库连接。 例如,您可以加入刚刚从数据库检索的结果集和内存结构(当然,这会受到某些限制)。 它提供了一种快速而肮脏的方式来“后处理”数据,有时比循环遍历数据集更具可读性(也更灵活!)。
然而,ColdFusion 并不是一个非常受欢迎的产品,我不打算详细说明它的原因。 我要问的是,其他语言是否支持这种技术(比如库,或多或少是相同的)? Python? 珀尔? 红宝石? PHP? 任何事物? 因为,在我看来,这个功能的潜力是巨大的,也许不在生产代码中,但如果您需要快速测试某些东西,它绝对是一个救星。 不用说,据我所知,SQL ColdFusion 为此使用的功能有些限制,但这个想法仍然很棒。
My experience of using Adobe ColdFusion, even if still somewhat limited, was absolutely joyful and pleasant.
Of all good things I could say about ColdFusion, one feature completely blew me off my feet. It might be neither very effective, or useful in production, but anyway, I am talking about the so-called "query of queries" feature, or the dbtype="query"
attribute of cfquery
. It allows you to run SQL statements against arbitrary datasets, not just a database connection. You can, for example, join a resultset, that you've just retrieved from the database and an in-memory structure (that is, of course, subject to certain limitations). It provides a quick-and-dirty way to kind of "post-process" the data, which can sometimes be much more readable (and flexible, too!), than, say, iterating through the dataset in a loop.
However, ColdFusion is not a very popular product and I am not going to go over the reasons why it is like that. What I am asking is, is there any support for this technique in other languages (like a library, that does more or less the same)? Python? Perl? Ruby? PHP? Anything? Because, to me it seems, that the potential of this feature is huge, maybe not in production code, but it is an absolute life-saver if you need to test something quickly. Needless to say, the SQL ColdFusion uses for this is somewhat limited, to my knowledge, but still, the idea is still great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
如果您没有找到任何可以像 ColdFusion 一样处理数据的工具,那么请记住它与其他编程语言配合得很好。 您始终可以在 CF 中进行繁重的查询处理,然后将处理逻辑包装在远程 CFC 中,并将它们公开为提供 JSON 的 Web 服务。
这将使您在尝试其他语言时受益于 ColdFusion 的优点。
如果您需要摆脱 CF,请尝试使用 Python 中的 SqlAlchemy,或者像其他海报所说的那样,Rails 和 LINQ 值得一试。
If you don't find anything that handles data as well as ColdFusion then remember it plays very well with other programming languages. You can always do the heavy query processing in CF then just wrap your processing logic in remote CFCs and expose them as web services serving up JSON.
That will let you benefit from what you find great about ColdFusion while trying out some other languages.
If you need to get away from CF try SqlAlchemy in Python, or like other posters said Rails and LINQ are worth playing with.
我不能使用 python、ruby、perl、php。 然而.Net有一个叫做LINQ的东西,它本质上是类固醇的QoQ。
i can't for python, ruby, perl, php. however .Net has something called LINQ which is essentially QoQ on steroids.
许多框架使用对象关系映射(ORM),它将数据库表转换为对象。
例如,使用 Rails 从模型中获取数据,而不是直接与数据库对话。 查询或查找以数组对象的形式返回,而数组对象又可以自行查询。
Lots of frameworks use object-relational mapping (ORM), which will convert your database tables to objects.
For example, using Rails you fetch data from a model instead of directly talking to the database. Queries, or finds, are returned as array objects, which can in turn be queried themselves.
您还可以在 .NET 中使用 LINQ 来完成此任务。 LINQ 可以让您查询对象以及数据库。
You can also accomplish this in .NET by using LINQ. LINQ will let you query objects as well as databases.
在对查询的查询进行性能分析时,我对它们的执行时间感到惊讶,在我的测试中我无法让它们在 10 毫秒内返回,而简单地对实际数据库的查询将在 1 毫秒或更短的时间内返回。 我的理解(至少在 CF MX 7 中)是,虽然这是一项有用的功能,但它并不是一个高度优化的功能。 我发现手动循环查询并执行条件逻辑来替换我尝试对查询的查询执行的操作要快得多。
话虽这么说,如果初始查询很慢,它比访问数据库要快。 只是不要认为它总是比进行更有创意的排序或初始查询更快,因为每个 QofQ 都远非瞬时。
In doing performance analysis of Query of Queries, I was surprised by their execution time, I could not get them to return in less than 10ms in my tests, where simply queries to the actual database would return in 1ms or less. My understanding (at least in CF MX 7) is that while this is a useful function, it is not a highly optimized one. I found it to be much faster to loop over the query manually doing conditional logic to replace what I was attempting to do with my query of queries.
That being said, it is faster than going to the database if the initial query is slow. Just don't use it thinking that it is going to always be faster than doing a more creative sort or initial query as each QofQ is far from instantaneous.
对于 Java,有三个项目值得一看,每个项目都有自己的优点和缺点,其中一些项目比其他项目更像 SQL。 JoSQL JoSQL,JXPath 和 MetaModel。
也许有一天我会弄清楚如何直接从 CF 下面的 Java 调用 QoQ。 ;)
For Java, there's three projects worth taking a look at, each with it's own positives and negatives, some more SQL like than others. JoSQL JoSQL, JXPath, and MetaModel.
Maybe one of these day's I'll figure out how to call a QoQ directly from the Java underneath CF. ;)
这种技术(ColdFusion 的查询中的查询)是最糟糕的想法之一。 它不仅将业务逻辑保留在数据库中,而且还会将代码中留下的少量业务逻辑随意地推到数据库中。
你需要的是一门好的语言,而不是弥补缺陷的坏技术。
Python 和 Ruby,以及不在列表中的其他语言(例如 C# 和 Haskell),都非常支持针对内存中对象编写任意且强大的查询。 这实际上是您想要的技术,而不是 ColdFusion 的查询中的查询。 针对内存中对象编写查询的技术是称为函数式编程的通用编程风格的一个方面。
This technique (ColdFusion's query-of-queries) is one of the worst ideas out there. Not only does it keep business logic in the database, but it takes what little business logic you have left in your code and shoves it out to the database just for spite.
What you need is a good language, not bad techniques to make up for deficiencies.
Python and Ruby, as well as other languages not on your list such as C# and Haskell, have exceptional support for writing arbitrary and powerful queries against in-memory objects. This is in fact the technique that you want, not ColdFusion's query-of-queries. The technique of writing queries against in-memory objects is an aspect of a general style of programming called functional programming.