Skip to content
Browse files

[enhance] runtime, postgres: Added --db-prefix command line option

  • Loading branch information...
1 parent b628657 commit 51c6fa13a715d93e2d4f9bccbed814b66ff2ae2b @BourgerieQuentin BourgerieQuentin committed Feb 27, 2013
Showing with 28 additions and 1 deletion.
  1. +28 −1 lib/stdlib/database/postgres/db.opa
View
29 lib/stdlib/database/postgres/db.opa
@@ -94,6 +94,31 @@ module DbPostgres{
}
+ private
+ function get_options(name){
+ (suffix, msg) = match(name){
+ case "_no_name" : ("", "")
+ case _ : (":{name}", "\"{name}\"")
+ }
+ CommandLine.filter({
+ title : "Options for Postgres database \"{msg}\"",
+ init : ~{name},
+ anonymous : [],
+ parsers : [
+ {CommandLine.default_parser with
+ names : ["--db-prefix{suffix}"],
+ description : "Set the Postgres database name, (default: {name})",
+ param_doc : "dbname",
+ function on_param(acc){
+ parser{
+ path=(.*) -> {no_params : {acc with name : Text.to_string(path)}}
+ }
+ }
+ },
+ ]
+ })
+ }
+
/**
* Opening a database and prepare statements.
* @param name Name of the database to open
@@ -104,8 +129,9 @@ module DbPostgres{
*/
function DbPostgres.t open(name, tables, statements, queries){
@spawn(
+ options = get_options(name)
/* 1 - Opening the postgres database */
- match(Postgres.connect(name, none, name)){
+ match(Postgres.connect(name, none, options.name)){
case ~{failure} :
Log.error0(name, "Can't open Postgres database {failure}")
@fail("DbPostgres.open")
@@ -114,6 +140,7 @@ module DbPostgres{
Log.info(c, "opened")
c = Postgres.authenticate(c)
check_error("Authentication", c)
+ Log.info(c, "authenticated")
/* 2 - Init tables
TODO: Add a way to unactivate table initialization */
List.iter(

0 comments on commit 51c6fa1

Please sign in to comment.
Something went wrong with that request. Please try again.