On Monday, April 11, 2016 at 7:24:23 PM UTC-7, Frank Pinto wrote:
>
> Hi all,
>
> I am new to this subject and ruby. My question is related to accessing
> information from one database in order to pass it along to another. For
> example: I have a database called User with a column name 'CDV' (which is a
> code about 8 digits long?) and 'nat_ID_number' (8 digits long?) and another
> one called 'Electors' with the same column. The thing is that the User db
> is used to stored information from people who want to be affiliated to my
> application essentially making it empty in the beginning, while the other
> already has information stored in it.
>
> So, when a new user is saved into the User db, he will be asked only to
> input the 'nat_id_number', then the idea is to use that input to go into
> the Elector db find the corresponding 'nat_ID_number' and then take the
> 'CDV' information from this db to the original one (User).
>
> My questions are as followed:
>
> 1) How can, using sequel, reference the Elector db? Is it through the
> 'DB.from(:Elector)' ? And how can I access only the right column? perhaps
> something like 'DB.from(:Elector[:nat_ID_number = :nat_ID_number])
>
Assuming a separate SQLite database, you should create a Sequel::Database
instance and assign it to a constant:
ElectorDB = Sequel.sqlite('/path/to/electors.sqlite3')
Generally such code would go in an initializer of some sort.
To look the CDV information from national id number:
cdv = ElectorDB[:electors].where(:nat_ID_number=>nat_ID_number).get(:CDV)
> 2) Where would I put that code? In the User controller?
>
You'd probably put that code to get the cdv either in the controller, in
the User model, or a service object of some kind.
> 3) What would be the function call from sequel to pass information from
> one to the other? Something like the last code at the bottom perhaps?
>
Since you are creating a user, after getting the CDV using the code above:
User.create(:CDV=>cdv)
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.