//
you're reading...
Chicagoboss, Erlang, PostgreSQL

Chicago Boss, PostgreSQL, SmartOS fun…

Been trying to get the Colosimo demo app working on my setup, and after digging through tons of code in various forks, lots of trial and error, I finally was able to get everything working.

Figured I should write it down so I don’t forget.

First, take a look at Installing Bcrypt for Chicago Boss Projects.

You will need bcrypt working for the example.

Out of all of the forks of Colosimo, I found this one to be best.

There’s good write up here also.

For the postgresql db I used the following:

create user colosimo with password 'colosimo';
create database colosimo with owner = colosimo;
grant all on DATABASE colosimo to colosimo;

create table colosimo_users (id SERIAL UNIQUE PRIMARY KEY, email VARCHAR(200), username VARCHAR(24), password VARCHAR(64), created TIMESTAMP);

For most part this worked good.

The only thing I ran into was because I added the created column that’s a timestamp type it took a bit of searching, testing, frustration, and confusion before I finally worked it out.

I don’t know if it helped but I pulled a current copy from here.

My rebar.config has these deps:

{deps, [
{boss, ".*", {git, "git://github.com/evanmiller/ChicagoBoss.git", "HEAD"}},
{bcrypt, "0.5.0", {git, "git://github.com/spawngrid/erlang-bcrypt.git", {branch, "rebar-update"}}},
{epgsql, ".*", {git, "git://github.com/wg/epgsql.git", "HEAD"}}
]}.

The issue I was having seems to be the format of the timestamp not lining up with the format used by epsql. I was hoping I could just pass the word “now” which works in a SQL insert, but because the DB layer is abstracted, that wasn’t working.

After a lot of trial and error, what finally worked was this (colosimo/src/lib/user_lib.erl):

register_user(Req) ->
TimeStamp = calendar:now_to_local_time(os:timestamp()),
HashedPassword = user_lib:get_hash(Req:post_param("password")),
NullappUser = nullapp_user:new(id, Req:post_param("email"), Req:post_param("username"), HashedPassword, TimeStamp),
NullappUser:save().

The TimeStamp needed to be converted to a {Date, Time} style, the docs for epgsql says it can take erlang.now(), but I couldn’t get that to work without converting the timestamp.

I also added to the model file (colosimosrc/model/colosimo_user.erl):
-module(nullapp_user, [Id, Email, Username, Password::string(), Created]).

That was it, or I forgot something, either way it’s pointing in the right direction.

Advertisements

Discussion

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s