metaSQL_Postgres.anubis 6.44 KB

                                      The Anubis Project

                            The Postgres dependant stuff for metaSQL. 


read tools/basis.anubis
read data_base/metaSQL.anubis
read data_base/postgres_client.anubis

public define Maybe(MetaSQL_Specific)
   metaSQL_make_specific
     (
       Word32              ip_address, 
       Word32              ip_port,               // usually: 5432 (IANA registered)
       String              user_name, 
       String              password,              // anything if no password required
       String              database_name,
     ).

   The same one but with encrypted connection to the database. 

public define Maybe(MetaSQL_Specific)
   metaSQL_make_specific
     (
       String                 server_name,   
       (Maybe(X509)) -> Bool  accept_policy,         // see web/multihost_http_server.anubis
       Word32                 ip_address, 
       Word32                 ip_port,               // usually: 5432 (IANA registered)
       String                 user_name, 
       String                 password,              // anything if no password required
       String                 database_name,
     ).




   --- That's all for the public part ! --------------------------------------------------



define One
   print
     (
       List(MaybeNull(ByteArray)) l
     ) =
   if l is 
     {
       [ ] then print(" |\n"), 
       [h . t] then print(" | "+
                          if h is 
                            {
                              null then "NULL", 
                              
                              not_null(ba) then to_string(ba)
                            }); print(t)
     }.

define String -> MetaSQL_Answer
   pg_to_meta
     (
       String -> PG_Answer qf
     ) =
   (String q) |-> if qf(q) is 
     {
       error(msg)             then error(format(msg)), 
       command_complete(msg)  then command_complete, 
       table(columns,rows)    then table(rows), 
       message_list(infos)    then informations(concat(map(
             ((Word8, ByteArray) p) |-> if p is (c,b) then to_decimal(c)+" "+to_string(b),infos),"\n"))
     }. 
    
    
define String
   to_database_type
     (
       MetaSQL_Type t
     ) =
   if t is 
     {
     anubis(_T)                          then "text",
     binary                              then "text"
     binary_or_null                      then "text"
     boolean                             then "boolean"
     boolean_or_null                     then "boolean"
     date                                then "date"
     date_or_null                        then "date"
     time                                then "time"
     time_or_null                        then "time"
     datetime                            then "timestamp"
     datetime_or_null                    then "timestamp"
     foreign(String table_name)          then "integer"
     foreign_or_null(String table_name)  then "integer"
     integer16                           then "integer"
     integer16_or_null                   then "integer"
     integer32                           then "integer"
     integer32_or_null                   then "integer"
     integer                             then "integer"
     integer_or_null                     then "integer"
     char(Int size)                      then "varchar("+size+")"
     char_or_null(Int size)              then "varchar("+size+")"
     text                                then "text"
     text_or_null                        then "text"
     }. 
     
   
    
    
define Maybe(String -> MetaSQL_Answer)
   make_query_function
     (
       Word32              ip_address, 
       Word32              ip_port,               // usually: 5432 (IANA registered)
       String              user_name, 
       String              password,              // anything if no password required
       String              database_name,
     ) = 
   if open_PG_connection
        (
          none, 
          ip_address,
          ip_port,
          user_name,
          password,
          database_name,
          (ByteArray a) |-> unique  // debugging tool not used here
        ) is 
     {
       error(pg_msg)    then failure, 
       ok(qf)           then success(pg_to_meta(qf))
     }. 
     
define Maybe(String -> MetaSQL_Answer)
   make_query_function
     (
       String                 server_name,   
       (Maybe(X509)) -> Bool  accept_policy,
       Word32                 ip_address, 
       Word32                 ip_port,               // usually: 5432 (IANA registered)
       String                 user_name, 
       String                 password,              // anything if no password required
       String                 database_name,
     ) = 
   if open_PG_connection
        (
          ssl(server_name,accept_policy), 
          ip_address,
          ip_port,
          user_name,
          password,
          database_name,
          (ByteArray a) |-> unique  // debugging tool not used here
        ) is 
     {
       error(pg_msg)    then failure, 
       ok(qf)           then success(pg_to_meta(qf))
     }. 
     

public define Maybe(MetaSQL_Specific)
   metaSQL_make_specific
     (
       Word32              ip_address, 
       Word32              ip_port,               // usually: 5432 (IANA registered)
       String              user_name, 
       String              password,              // anything if no password required
       String              database_name,
     ) =
   if make_query_function(ip_address,ip_port,user_name,password,database_name) is
     {
       failure then failure, 
       success(qf) then 
         success(specific(database_name,qf,to_database_type))
     }. 
    

   The same one but with encrypted connection to the database. 

public define Maybe(MetaSQL_Specific)
   metaSQL_make_specific
     (
       String                 server_name,   
       (Maybe(X509)) -> Bool  accept_policy,         // see web/multihost_http_server.anubis
       Word32                 ip_address, 
       Word32                 ip_port,               // usually: 5432 (IANA registered)
       String                 user_name, 
       String                 password,              // anything if no password required
       String                 database_name,
     ) =
   if make_query_function(server_name,accept_policy,ip_address,ip_port,user_name,password,database_name) is
     {
       failure then failure, 
       success(qf) then 
         success(specific(database_name,qf,to_database_type))
     }.