Property definitions

postgresql $ Postgres :: defaultinit
# A connection to a Postgres database
class Postgres
  private var native_connection: NativePostgres

  # Is the connection closed?
  var is_closed = true

  # Open the connnection with the database using the `conninfo`
  init open(conninfo: Text)
  do
    init(new NativePostgres.connectdb(conninfo))
    if native_connection.status.is_ok then is_closed = false
  end

  # Close this connection with the database
  fun finish
  do
    if is_closed then return

    is_closed = true

    native_connection.finish
  end

  # Prepares the statement `query` with `stmt_name` to be executed later
  #
  # `num_params` specifies the number of parameters expected at the statement
  # execution.
  #
  # See `exec_prepared` for execution.
  fun prepare(stmt_name:String, query:String, num_params: Int):PGResult do return new PGResult(native_connection.prepare(stmt_name, query, num_params))

  # Execute prepared statement named `stmt_name` with `values`
  #
  # * `num_params` specifies the number of parameters given to the prepared statement
  # * `param_lengths` specifies the length of each parameters
  # * `param_formats` and `result_format` specifies the format used as input/output.
  #   Should be 0 for text results, 1 for binary.
  #
  # See `prepare`.
  fun exec_prepared(stmt_name: String, num_params: Int, values: Array[String], param_lengths: Array[Int], param_formats: Array[Int], result_format: Int):PGResult do
    return new PGResult(native_connection.exec_prepared(stmt_name, num_params, values, param_lengths, param_formats, result_format))
  end

  # Executes a `query` and returns the raw `PGResult`
  fun raw_execute(query: Text): PGResult do return new PGResult(native_connection.exec(query))

  # Execute the `sql` statement and returns `true` on success
  fun execute(query: Text): Bool do return native_connection.exec(query).status.is_ok

  # Create a table on the DB with a statement beginning with "CREATE TABLE ", followed by `rest`
  #
  # This method does not escape special characters.
  fun create_table(rest: Text): Bool do return execute("CREATE TABLE " + rest)

  # Insert in the DB with a statement beginning with "INSERT ", followed by `rest`
  #
  # This method does not escape special characters.
  fun insert(rest: Text): Bool do return execute("INSERT " + rest)

  # Replace in the DB with a statement beginning with "REPLACE", followed by `rest`
  #
  # This method does not escape special characters.
  fun replace(rest: Text): Bool do return execute("REPLACE " + rest)

  # The latest error message on the connection an empty string if none
  fun error: String do return native_connection.error

  # The status of this connection
  fun is_valid: Bool do return native_connection.status.is_ok

  # Resets the connection to the database
  fun reset do native_connection.reset
end
lib/postgresql/postgres.nit:59,1--132,3