Hi Jeremy,

On Sun, Aug 12, 2012 at 2:39 PM, Christian MICHON
<[email protected]> wrote:
> On Thu, Aug 9, 2012 at 11:35 PM, Jeremy Evans <[email protected]> wrote:
>> On Wednesday, August 1, 2012 12:38:15 PM UTC-7, Jeremy Evans wrote:
>>>
>>> In a fairly unusual step for Sequel, I have pushed another public branch
>>> to GitHub, named consvals.  From the commit message:
>>>
>>> The extension allows you to create database constraints that mirror
>>> model validations when creating and altering tables.  It adds
>>> validation to a separate table.  The plugin reads the metadata
>>> from that table, and uses it to automatically validate your models
>>> before saving.
>>>
>>> The advantage to doing so is that your validations are only specified
>>> in one place, but are enforced both at the model level and at the
>>> database level.  This is better for data integrity, since it
>>> enforces the validation for all rows in the database, so changes
>>> made by external programs or via the dataset layer are still
>>> covered.
>>>

This sounds cool.

>>>
>>> I've thought about doing this for a long time, but only recently figured
>>> out a good way to implement this.  Usually, I would just merge something
>>> like this into the master branch, but as the extension creates its own
>>> table, it will be quite a pain to modify the schema for the table later.  To
>>> avoid potential problems in the future, I would like to get some feedback
>>> about this branch before I merge it.  I plan on leaving this branch publicly
>>> available for one week for feedback.  After I week, I'll decide whether to
>>> merge it as-is, merge it with changes, or not merge it at all, depending on
>>> the feedback received.  If you have any feelings about this one way or the
>>> other, please make them known.
>>
>>
>> I haven't received much feedback on this, so I would still appreciate
>> additional review/comments.
>>

I just tried on H2 database. I did not think the backend SQL would
hold the constraint, as this seemed too good to be true, but it works
out of the box as advertised.

I did the following, and manage to check saved validations using H2
without Sequel:

require 'sequel'
DB=Sequel.connect 'jdbc:h2:test'
DB.extension(:constraint_validations)
DB.create_constraint_validations_table
DB.create_table(:humans) do
  primary_key :id
  String :name
  validate do
    presence :id
    min_length 5, :name
  end
end

class Human < Sequel::Model(DB[:humans])
end

o = Human.new
o.name = 'Bob'
o.save

o.name = 'Bobby'
o.save

One problem though: using this code, my saved Human object 'Bobby'
gets its id = 2, because 1st save did not work: is this the expected
behavior?

-- 
Christian

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to