On Feb 13, 3:11 am, sohdubom <[email protected]> wrote:
> Ok, so it's ok to do code like this?
>
> -----------------------------------------------
> # establishes the connection
> DB = Sequel.connect "sqlite://models/test.db",
>   :max_connections => 10,
>   :encoding => 'unicode',
>   :logger => Logger.new('models/test.log')
>
> # will open a connection, because of the create table in user.rb class
> require "models/user.rb"
> load "models/user.rb"
>
> DB.disconnect
>
> -----------------------------------------------
>
> -----------------------------------------------
> get '/users' do
>   @users = User.all   # open the connection
>   DB.disconnect       # close it
>   haml :'/user/index'
> end
> -----------------------------------------------
>
> -----------------------------------------------
> class User < Sequel::Model(:users)
>   set_schema do
>     primary_key :id
>     varchar :username
>     varchar :password
>     timestamp :created_at
>   end
>   if !(table_exists?)
>     create_table
>     User.create :username => 'johndoe', :password => '123654',
>                 :created_at => Time.now
>     User.create :username => 'zehmaneh', :password => '123654',
>                 :created_at => Time.now
>   end
> end
> -----------------------------------------------
>
> So probably that's why it's a good idea to use the 'vendor' dir with
> the init.rb
> file to encapsulate the establishment of the connection there?

That should work.

Note that you should have a very good reason for doing this.  The
typical reason for a client-server database is that the client (your
app) is far from the (database) server, and you don't want the
connection being lost.  For SQLite, that's not generally true, so if
you could share your reason, that would be helpful.

Thanks,
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