Skip to content

Instantly share code, notes, and snippets.

diff --git a/lib/dm-core/property.rb b/lib/dm-core/property.rb
index c8f5aa1..e92e81c 100644
--- a/lib/dm-core/property.rb
+++ b/lib/dm-core/property.rb
@@ -688,7 +688,7 @@ module DataMapper
if primitive == Integer
# only typecast a String that looks like a number
case value.to_s
- when /\A((?:0|[1-9]\d*)(?:\.\d+)?)\z/ then $1.to_i # integer or float
+ when /\A(-?(?:0|[1-9]\d*)(?:\.\d+)?)\z/ then $1.to_i # integer or float
# If you'd like to try DataMapper 0.10 on the bleeding edge, you can do the following:
# Download all the repositories necessary to make DataMapper work
git clone git://github.com/datamapper/extlib.git
git clone git://github.com/datamapper/do.git
git clone git://github.com/datamapper/dm-core.git
git clone git://github.com/datamapper/dm-more.git
# Switch each repo to the "next" (0.10) branch, and install.
cd extlib
require 'rubygems'
require 'dm-core'
class BigDec
include DataMapper::Resource
property :id, Serial
property :value, BigDecimal
end
#DataMapper.setup(:default, :adapter=>:in_memory)
module Addressable
include DataMapper::Resource
is :remixable
# ...
end
module Linkable
include DataMapper::Resource
is :remixable
# ...
module Addressable
include DataMapper::Resource
is :remixable
# ...
end
module Linkable
include DataMapper::Resource
is :remixable
# ...
require 'dm-core'
require 'dm-aggregates'
DataMapper::Logger.new(STDOUT, :debug)
DataMapper.setup(:default, "mysql://localhost/dm_specs")
class CrawledPage
include DataMapper::Resource
property :id, Serial
belongs_to :crawling_run
or_op = DataMapper::Query::Conditions::OrOperation.new
and_op = DataMapper::Query::Conditions::AndOperation.new
or_op << DataMapper::Query::Conditions::Comparison.new(:eql, Human.last_name, "Obama")
or_op << DataMapper::Query::Conditions::Comparison.new(:eql, Human.last_name, "Clinton")
and_op << DataMapper::Query::Conditions::Comparison.new(:eql, Human.sex, "M")
and_op << or_op
q = DataMapper::Query.new(Human.repository,Human, :conditions => and_op)
q.valid? # => true

I would like to give Query some logical grounding, so we can guarantee particular types of behavior.

The model that make sense for this is to develop a small algebra. This algebra won't actually be a relational algebra for a couple reasons. First, DataMapper's primary goal isn't to adhere directly to relational algebra because there are supported query engines which are not capable of doing so. Second query objects themselves aren't actually representations of joins. They're representations of criteria on a dataset. It may be the case that the dataset being queried is the result of an additional join operation, if the data engine being queried is capable of satisfying such a join object.

Properties of a Query

  • Repository
  • Model
  • Fields
  • Conditions
caelesta:wimple knowtheory$ rvm uninstall jruby
Removing /Users/knowtheory/.rvm/rubies/jruby-1.4.0...
caelesta:wimple knowtheory$ rvm install jruby
/Users/knowtheory/.rvm/src/jruby-1.4.0 has already been extracted.
Building Nailgun
Installing JRuby to /Users/knowtheory/.rvm/rubies/jruby-1.4.0
Installing jruby-openssl
caelesta:wimple knowtheory$ rvm jruby
caelesta:wimple knowtheory$ which gem
/Users/knowtheory/.rvm/rubies/jruby-1.4.0/bin/gem
class Comment
include DataMapper::Resource
property :id, Serial
property :body, Text
belongs_to :commentor, "User"
end