Forum: Ruby on Rails Is there a guide for using ERBSQL?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B614e42d18c609ac4585d0aa0b13d856?d=identicon&s=25 Jim Jeffers (Guest)
on 2005-12-19 07:21
(Received via mailing list)
I'm not sure I completely understand the benefits of using ERBSQL or
how to use it.  Google searches have proved it to be rather
undocumented.

 From what I understand the embedded ruby sql allows you to write sql
that's easier to deploy via the create_db script and also more
portable to postgres, myslq, or whatever.

But what I can't find is a resource that explains the preset
constants or how to configure them if need be.  For example the ERB
that comes with the saltedlogingenerator for rails looks like this:

CREATE TABLE users (
   id <%= @pk %>,
   login VARCHAR(80) NOT NULL,
   salted_password VARCHAR(40) NOT NULL,
   email VARCHAR(60) NOT NULL,
   firstname VARCHAR(40) default NULL,
   lastname VARCHAR(40) default NULL,
   salt CHAR(40) NOT NULL,
   verified INT default 0,
   role VARCHAR(40) default NULL,
   security_token CHAR(40) default NULL,
   token_expiry <%= @datetime %> default NULL,
   created_at <%= @datetime %> default NULL,
   updated_at <%= @datetime %> default NULL,
   logged_in_at <%= @datetime %> default NULL,
   deleted INT default 0,
   delete_after <%= @datetime %> default NULL
) <%= @options %>;

 From viewing the example I get the gist of how it works and what's
going on but what if I just want to make a date field instead of a
datetime etc. etc.  Also what if I want to use a different set of
options for the table instead of the default ones generated by
create_db.

Finally, I am using the following sql to signify my foreign keys but
these statements create a syntax error when I run create_db:
constraint fk_pages_section foreign key (section_id) references
sections(id)

Any advice or links to a guide on working with erbsql?  Also any
advice as to how to signify the foreign keys the erbsql way?
3a83969376c805ef5b6042191fdb0ff3?d=identicon&s=25 Andreas S. (andreas)
on 2005-12-19 18:40
Jim Jeffers wrote:
> I'm not sure I completely understand the benefits of using ERBSQL or
> how to use it.  Google searches have proved it to be rather
> undocumented.
>
>  From what I understand the embedded ruby sql allows you to write sql
> that's easier to deploy via the create_db script and also more
> portable to postgres, myslq, or whatever.
>
> But what I can't find is a resource that explains the preset
> constants or how to configure them if need be.

Look into lib/db_structure.rb. That's where I put that file originally,
but the creator of the gem might have moved it somewhere else.

Anyway, you shouldn't bother with erbsql. Migrations are a lot better to
keep your db structure. You should find a lot on this topic with Google.
This topic is locked and can not be replied to.