0

Is it possible to convert this SQL Query Request into Datamapper?

SELECT twitchtv 
FROM twitchtvsts 
WHERE twitchtvsts.user_id = thisisavaraible


get '/watch/:id' do |id|
    erb :mystream 
    result = repository(:default).adapter
                             .select(
                                     'SELECT twitchtv 
                                      FROM twitchtvsts 
                                      WHERE twitchtvsts.user_id = id'
                                    )
    puts result
Arup Rakshit
  • 116,827
  • 30
  • 260
  • 317
user2945872
  • 393
  • 3
  • 4
  • 12

1 Answers1

1

Write as below :

Twitchtvsts.all( :fields => [:twitchtv ], 
                 :conditions => { :user_id => id_var }           
               )

Read this Projecting only specific properties .

Arup Rakshit
  • 116,827
  • 30
  • 260
  • 317
  • It seems like this lists all my entries but I only want them to list one. How do I get the variable?? {id}? here is my output on terminal when I have id as variable SELECT twitchtv FROM twitchtvsts WHERE twitchtvsts.user_id = id gsl day9tv dendi dotacinema – user2945872 Feb 26 '14 at 19:42
  • get '/watch/:id' do |id| erb :mystream result = repository(:default).adapter .select( 'SELECT twitchtv FROM twitchtvsts WHERE twitchtvsts.user_id = id' ) puts result – user2945872 Feb 26 '14 at 19:43
  • @user2945872 what is your problem now / – Arup Rakshit Feb 26 '14 at 19:45
  • how do I get a varible into the String # dosents wwork – user2945872 Feb 26 '14 at 19:48
  • thank you very much but I still have a bit of problem. Thing is that it gets as # now.How do I convert this into string like the thing I have insert into SQL? Do you copy what I'm saying? :) – user2945872 Feb 26 '14 at 20:00