Is there a guide for using ERBSQL?


#1

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?


#2

Jim J. 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.