Re: Is it possible to get primary key on the fly?

2017-01-13 Thread Jeremy Evans
On Friday, January 13, 2017 at 5:10:23 PM UTC-8, Septian Hari wrote:
>
> Hello guys, 
> as the title says, i wanted to get primary key from a table. 
> Is there any method from sequel that provide that? 
>

You can get that information using Database#schema, and looking for 
:primary_key entries for each column:

DB.schema(:table).select{|(c, h)| h[:primary_key]}.map(&:first)

This returns an array as tables can have multiple primary key columns.

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sequel-talk+unsubscr...@googlegroups.com.
To post to this group, send email to sequel-talk@googlegroups.com.
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.


Is it possible to get primary key on the fly?

2017-01-13 Thread Septian Hari
Hello guys,
as the title says, i wanted to get primary key from a table.
Is there any method from sequel that provide that?

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sequel-talk+unsubscr...@googlegroups.com.
To post to this group, send email to sequel-talk@googlegroups.com.
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.