On Sep 24, 10:13 am, Adrian Madrid <[email protected]> wrote:
> I'm interested in using UUIDs instead of integer for primary keys in some of
> my models and I'm not sure what would be the best way to implement it in
> Sequel. I'm thinking something like this:

The best practice would be to use integer keys instead of UUIDs, IMO.
UUIDs primary keys are only helpful in fairly limited circumstances
(e.g. partitioned databases), so unless you really need them, I'd
avoid using them.

> class ExampleMigration < Sequel::Migration
>
>   def up
>     create_table(:examples) do
>       String   :id, :size => 36, :unique => true
>       String   :name
>       DateTime :created_at
>       DateTime :updated_at
>     end
>   end
>
>   def down
>     drop_table :examples
>   end
>
> end
>
> class Example < Sequel::Model
>
>   def before_create
>     super
>     self[:id] = CustomUUID.generate
>   end
>
> end
>
> What would you do differently and why? Is there any possible problems with
> this type of primary key? Any comments would be appreciated but please be
> gentle ;-)

Your implementation is probably the best way to implement them.  There
isn't real problem using them (Sequel should work with UUID primary
keys just fine), other than the performance impact of using 36
character strings over simple integers.  I just don't see any
advantages unless you are using a partitioned database.

Jeremy
--~--~---------~--~----~------------~-------~--~----~
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