阅读更多

8顶
0踩

编程语言

原创新闻 Sequel 3.2.0 发布

2009-07-03 13:48 by 见习记者 night_stalker 评论(5) 有10103人浏览
Sequel 是轻量级的 Ruby 数据库访问工具。

广告若干
------------
真的很酷,用过就知道它比 ActiveRecord 牛在哪里了

* Sequel provides thread safety, connection pooling and a concise DSL for constructing database queries and table schemas.

* Sequel also includes a lightweight but comprehensive ORM layer for mapping records to Ruby objects and handling associated records.

* Sequel supports advanced database features such as prepared statements, bound variables, stored procedures, master/slave configurations, and database sharding.

* Sequel makes it easy to deal with multiple records without having to break your teeth on SQL.

* Sequel currently has adapters for ADO, Amalgalite, DataObjects, DB2, DBI, Firebird, Informix, JDBC, MySQL, ODBC, OpenBase, Oracle, PostgreSQL and SQLite3.


新特性
------------

* Common table expressions (CTEs) are now supported.  CTEs use the SQL WITH clause, and specify inline views that queries can use. They also support a recursive mode, where the CTE can recursively query its own output, allowing you do do things like load all branches for a given node in a plain tree structure.

  The standard with takes an alias and a dataset:
    DB[:vw].with(:vw, DB[:table].filter{col < 1})
    # WITH vw AS (SELECT * FROM table WHERE col < 1)
    # SELECT * FROM vw


  The recursive with takes an alias, a nonrecursive dataset, and a
  recursive dataset:
    DB[:vw].with_recursive(:vw,
      DB[:tree].filter(:id=>1),
      DB[:tree].join(:vw, :id=>:parent_id).
                select(:vw__id, :vw__parent_id))
    # WITH RECURSIVE vw AS (SELECT * FROM tree
    #     WHERE (id = 1)
    #     UNION ALL
    #     SELECT vw.id, vw.parent_id
    #     FROM tree
    #     INNER JOIN vw ON (vw.id = tree.parent_id))
    # SELECT * FROM vw


  CTEs are supported by Microsoft SQL Server 2005+, DB2 7+, Firebird 2.1+, Oracle 9+, and PostgreSQL 8.4+.

* SQL window functions are now supported, and a DSL has been added to ease their creation.  Window functions act similarly to aggregate functions but operate on sliding ranges of rows.

  In virtual row blocks (blocks passed to filter, select, order, etc.) you can now provide a block to method calls to change the default behavior to create functions that weren't possible previously.  The blocks aren't called, but their presence serves as a flag.

  What function is created depends on the arguments to the method:

  * If there are no arguments, an SQL::Function is created with the name of method used, and no arguments.  Previously, it was not possible to create functions without arguments using the virtual row block DSL.  Example:
      DB.dataset.select{version{}} # SELECT version()


  * If the first argument is:*, an SQL::Function is created with a single wildcard argument (*).  This is mostly useful for count:
      DB[:t].select{count(:*){}} # SELECT count(*) FROM t


  * If the first argument is:distinct, an SQL::Function is created with the keyword DISTINCT prefacing all remaining arguments. This is useful for aggregate functions such as count:
      DB[:t].select{count(:distinct, col1){}}
      # SELECT count(DISTINCT col1) FROM t


  * If the first argument is:over, the second argument, if provided, should be a hash of options to pass to SQL::Window.  The options hash can also contain :*=>true to use a wildcard argument as the function argument, or :args=>... to specify an array of arguments to use as the function arguments.
      DB[:t].select{rank(:over){}} # SELECT rank() OVER ()
      DB[:t].select{count(:over, :*=>true){}} # SELECT count(*) OVER ()
      DB[:t].select{sum(:over, :args=>col1,
                    :partition=>col2, :order=>col3){}}
      # SELECT sum(col1) OVER (PARTITION BY col2 ORDER BY col3)


  PostgreSQL also supports named windows.  Named windows can be specified by Dataset#window, and window functions can reference them using the:window option.

* Schema information for columns now includes a:ruby_default entry which contains a ruby object that represents the default given by the database (which is stored in:default).  Not all:default entries can be parsed into a :ruby_default, but if the schema_dumper extension previously supported it, it should work.

* Methods to create compound datasets (union, intersect, except), now take an options hash instead of a true/false flag.  The previous API is still supported, but switching to specifying the ALL setting using :all=>true is recommended.

  Additionally, you can now set :from_self=>false to not wrap the returned dataset in a "SELECT * FROM (...)".

* Dataset#ungraphed was added that removes the graphing information from the dataset.  This allows you to use Dataset#graph for the automatic aliasing, or #eager_graph for the automatic aliasing and joining, and then remove the graphing information so that the resulting objects will not be split into subhashes or associations.

* There were some introspection methods added to Dataset to describe which capabilities that dataset does or does not support:
    supports_cte?
    supports_distinct_on?
    supports_intersect_except?
    supports_intersect_except_all?
    supports_window_functions?


  In addition to being available for the user to use, these are also used internally, so attempting to use a CTE on a dataset that doesn't support it will raise an Error.

* Dataset#qualify was added, which is like qualify_to with a default of first_source.

  Additionally, qualify now affects PlaceholderLiteralStrings.  It doesn't scan the string (as Sequel never attempts to parse SQL), but if you provide the column as a symbol placeholder argument, it will qualify it.

* You can now specify the table and column Sequel::Migrator will use to record the current schema version.  The new Migrator.run method must be used to use these new options.

* The JDBC adapter now accepts :user and :password options, instead of requiring them to be specified in the connection string and handled by the JDBC driver.  This should allow connections to Oracle using the Thin JDBC driver.

* You can now specify the max_connections, pool_timeout, and single_threaded settings directly in the connection string:
    postgres:///database?single_threaded=t
    postgres:///database?max_connections=10&pool_timeout=20


* Dataset#on_duplicate_key_update now affects Dataset#insert when using MySQL.

* You can now specify the:opclass option when creating PostgreSQL indexes.  Currently, this only supports a single operator class for all columns.  If you need different operator classes per column, please post on sequel-talk.

* Model#autoincrementing_primary_key was added and can be used if the autoincrementing key isn't the same as the primary key.  The only likely use for this is on MySQL MyISAM tables with composite primary keys where only one of the composite parts is autoincrementing.

* You can now use database column values as search patterns and specify the text to search as a String or Regexp:
    String.send(:include, Sequel::SQL::StringMethods)
    Regexp.send(:include, Sequel::SQL::StringMethods)

    'a'.like(:x)  # ('a' LIKE x)
    /a/.like(:x)  # ('a' ~ x)
    /a/i.like(:x) # ('a' ~* x)
    /a/.like(:x, 'b') # (('a' ~ x) OR ('a' ~ 'b'))


* The Dataset#dataset_alias private method was added.  It can be overridden if you have tables named t0, t1, etc and want to make sure the default dataset aliases that Sequel uses do not clash with existing table names.

* Sequel now raises an Error if you call Sequel.connect with something that is not a Hash or String.

* bin/sequel now accepts a -N option to not test the database connection.

* An opening_databases.rdoc file was added to the documentation directory, which should be a good introduction for new users about how to set up your Database connection.


其它改进
------------

* MySQL native adapter SELECT is much faster than before, up to 75% faster.

* JDBC SELECT is about 10% faster than before.  It's still much slower than the native adapters, due to conversion issues.

* bin/sequel now works with a YAML file on ruby 1.9.

* MySQL foreign key table constraints have been fixed.

* Database#indexes now works on PostgreSQL if the schema used is a Symbol.  It also works on PostgreSQL versions all the way back to 7.4.

* Graphing of datasets with dataset sources has been fixed.

* Changing a columns name, type, or NULL status on MySQL now supports a much wider selection of column defaults.

* The stored procedure code is now thread-safe.  Sequel is thread-safe in general, but due to a bug the previous stored procedure code was not thread-safe.

* The ODBC adapter now drops statements automatically instead of requiring the user to do so manually, making it more similar to other adapters.

* The single_table_inheritance plugin no longer overwrites the STI field if the field already has a value.  This allows you to use create in the eneric class to insert a value that will be returned as a subclass:
    Person.create(:kind => "Manager")


* When altering colums on MySQL, :unsigned, :elements, :size and other options given are no longer ignored.

* The PostgreSQL shared adapter's explain and analyze methods have been fixed, they had been broken in 3.0.

* Parsing of the server's version is more robust on PostgreSQL. It should now work correctly for 8.4 and 8.4rc1 type versions.


后向兼容
------------

* Dataset#table_exists? has been removed, since it never worked perfectly.  Use Database#table_exists? instead.

* Model.grep now calls Dataset#grep instead of Enumerable#grep. If you are using Model.grep, you need to modify your application.

* The MSSQL shared adapter previously used the :with option for storing the NOLOCK setting of the query.  That option has been renamed to table_options, since :with is now used for CTEs. This should not have an effect unless you where using the option manually.

* Previously, providing a block to a method calls in virtual row blocks did not change behavior, where now it causes a different code path to be used.  In both cases, the block is not evaluated, but that may change in a future version.

* Dataset#to_table_reference protected method was removed, as it was no longer used.

* The pool_timeout setting is now converted to an Integer, so if you used to pass in a Float, it no longer works the same way.

* Most files in adapters/utils have been removed, in favor of integrating the code directly into Database and Dataset.  If you were previously checking for the UnsupportedIntersectExcept or related modules, use the Dataset introspection methods instead (e.g. supports_intersect_except?).

* If you were using the ODBC adapter and manually dropping returned statements, you should note that now statements are dropped automatically, and the execute method doesn't return a statement object.

* The MySQL adapter on_duplicate_key_update_sql is now a private method.

* If you were modifying the :from dataset option directly, note that Sequel now expects this option to be preprocessed.  See the new implementation of Dataset#from for an idea of the changes required.

* Dataset#simple_select_all? now returns false instead of true for a dataset that selects from another dataset.

Thanks,
Jeremy

* {Website}
http://sequel.rubyforge.org

* {Source code}
http://github.com/jeremyevans/sequel

* {Bug tracking}
http://code.google.com/p/ruby-sequel/issues/list

* {Google group}
http://groups.google.com/group/sequel-talk

* {RDoc}
http://sequel.rubyforge.org/rdoc
来自: ruby-forum
8
0
评论 共 5 条 请登录后发表评论
5 楼 oldrev 2009-07-07 20:37
一直用 DataMapper,不知道跟DM比哪个的数据库兼容性好点?
4 楼 jjx 2009-07-04 11:37
感觉是sqlalchemy 的python expression翻版,不过没有sqlalchemy 的那种高度
3 楼 whaosoft 2009-07-04 01:04
看起来好像不错 我试试
2 楼 鹤惊昆仑 2009-07-03 21:51
very cool
1 楼 yangzhihuan 2009-07-03 18:31
操作数据库的DSL

发表评论

您还没有登录,请您登录后再发表评论

相关推荐

  • VB.NET使用多线程

    这是一个简单的VB.NET使用托管的多线程程序。防止界面假死。教你怎么使用Delegate来传递参数。 代码简单。 抛砖引玉。谢谢!

  • 在你的VB.NET应用程序中使用多线程 (转)

    在你的VB.NET应用程序中使用多线程 (转)[@more@]在你的vb.NET应用程序中使用多线程 很长时间以来,开发人员一直要求微软为VB增加更多的线程功能——这一点在VB.NET中终于实现了。vb6不支持创建多线程的...

  • VB.NET 多线程开发速成教程(附实例)

    过去,我们利用VB开发多线程的应用程序时,是一件很令人痛苦的事,经常是多线程的程序运行是会变成多错误的程序!但在VB.NET中,这种状况已经大为改观。现在,我们利用VB.NET处理多线程和利用JAVA处理多线程一样简单了。下面我们就举个例子,来看看VB.NET的多线程吧! 对于初次接触多线程的人,很适合的入门教程。

  • vb.net的多线程

    Dim tUdpThread As Thread Dim tBroadCast As Thread Dim tBroadCastExit As Thread Dim startUdpThread As ClassStartUdpThread = New ClassStartUdpThread() tUdpThread = New Thread(AddressOf sta...

  • 如何创建带参数多线程程序

    这是用VB.net演示的一个演示多线程的程序,可以给初学VB.net的线程的同志做个很好的例子参考。

  • VB.NET向Word VBA传递参数,并调用Word VBA生成Word报告或PDF文档

    之前我们看到用VB.NET调用Excel VBA的例子比较多,本次是使用VB.NET向Word VBA传递参数,并调用Word VBA生成Word报告或PDF文档。 在Word VBA中,可访问数据库,获得自己想展示的数据,灵活度比较高。 运行环境:VS2017 Word2016

  • vb.net中委托的例子

    用vb.net编写的一个关于如何声明、调用委托的一个小例子

  • [VB.NET]关于线程和委托的问题

    google_ad_client = "pub-8333940862668978";/* 728x90, 创建于 08-11-30 */google_ad_slot = "4485230109";google_ad_width = 728;google_ad_height = 90;//<script type="text/javascript"

  • VB的委托和事件

    委托和事件 委托,这个词一听被邪乎。几年前我还以为和律师什么的有关系。可事实上“委托”就是System.Delegate类。它是一个类,这就意味着它是一个数据类型,而且是一个引用类型。它能够引用对象的方法(实例方法)和类的方法(静态方法、在VB里的Shared方法)。 使用委托可以概括为三步:声明、实例化、调用。 Public Class Class1    Share

  • 在VB.NET中如何使用多线程详细知识

    VB.NET编程语言的推出,帮助开发人员极大的提高了开发效率。在这里我们会为大家介绍一下VB.NET多线程的使用方法,从而了解这门语言给我们带来的方便性,及特殊的编程方式,方便大家理解。 很长时间以来,开发人员一直要求微软为VB增加更多的线程功能--这一点在VB.NET中终于实现了。VB6不支持创建多线程的EXE、DLL以及OCX.但这种措词容易引起误解...

  • 复习一下 .Net: delegate(委托)、event(事件) 的基础知识,从头到尾实现事件!

    /*.Net 的 delegate 与 event 的实现是不可分的!属于基础知识!有这样一道 .Net/C# 试题:请以事件的概念实现: 控制台屏幕录入任意字符串,并回显 "你键入了:" + 你刚才键入的字符串,如果键入 "q",退出程序,运行结束!.Net 的 delegate 与 event 的实现是不可分的!属于基础知识!写惯了 Windows 下的事件响应程序,真正从头到

  • [VB.NET]单元一VB.NET初识

      google_ad_client = "pub-8333940862668978";/* 728x90, 创建于 08-11-30 */google_ad_slot = "4485230109";google_ad_width = 728;google_ad_height = 90;//<script type="text/javascript"

  • vb.net2019-多线程并行计算(1)

    Imports System Imports System.Threading Module Module1 Sub Main() Dim mythread1 As Thread Dim mythread2 As Thread Dim mythread3 As Thread '创建线程对象 my...

  • 使用 Visual Basic .NET 进行多线程编程

    摘要:.NET 框架提供了新的类,可以方便地创建多线程应用程序。本文介绍如何使用 Visual Basic® .NET 的多线程编程技术来开发效率更高、响应速度更快的应用程序。 目录 简介 多线程处理的优点 创建新线程 同步线程 线程计时器 取消任务 总...

  • 彻底弄懂JS事件委托的概念和作用

    一、写在前头 接到某厂电话问什么是事件代理的时候,一开始说addEventListener,然后他说直接绑定新的元素不会报dom不存在的错误吗?然后我就混乱了,我印象中这个方法是可以绑定新节点的。后面才知道,原来他要考察的是事件委托(代理)的原理,他指的是未来还不清楚会创建多少个节点,所以没办法实现给他们注册事件。 二、事件委托(事件代理)的作用? 为了方便理解,我先把事件委托的作用写一下。...

  • VB.NET 中的委托与事件一例

    Namespace Events Public Delegate Sub NumberReachedEventHandler(ByVal sender As Object, ByVal e As NumberReachedEventArgs) Public Class Counter Public Event NumberReached As NumberRea...

  • VB.NET多线程使用例子

    VB.NET多线程使用例子 ’定义Delegate Private Delegate Function testDelegate(ByVal objParam As Object) As String ‘多线程调用 Public Function testIf(ByVal objParam As Object) As String Dim testCall As New test

  • vb.net为什么要用 委托  理解 心得体会

    vb.net为什么要用 委托 理解 心得体会 2020年4月29日 18:47 一个语法的出现,一般是为了解决现有方法解决不了问题. 这几天 看了 委托 的用法,很多网友 都讲了一些 自己的理解. 在这里 感谢他们. 但是 很多网友讲的例子 都是 可以直接使用 对象.方法 来实现,没有讲到 为什么要使用委托. 或者 有的 说了 为了 解耦 举...

Global site tag (gtag.js) - Google Analytics