A connection to a Postgres database

Introduced properties

fun create_table(rest: Text): Bool

postgresql :: Postgres :: create_table

Create a table on the DB with a statement beginning with "CREATE TABLE ", followed by rest
init defaultinit(native_connection: NativePostgres)

postgresql :: Postgres :: defaultinit

fun error: String

postgresql :: Postgres :: error

The latest error message on the connection an empty string if none
fun exec_prepared(stmt_name: String, num_params: Int, values: Array[String], param_lengths: Array[Int], param_formats: Array[Int], result_format: Int): PGResult

postgresql :: Postgres :: exec_prepared

Execute prepared statement named stmt_name with values
fun execute(query: Text): Bool

postgresql :: Postgres :: execute

Execute the sql statement and returns true on success
fun finish

postgresql :: Postgres :: finish

Close this connection with the database
fun insert(rest: Text): Bool

postgresql :: Postgres :: insert

Insert in the DB with a statement beginning with "INSERT ", followed by rest
fun is_closed: Bool

postgresql :: Postgres :: is_closed

Is the connection closed?
protected fun is_closed=(is_closed: Bool)

postgresql :: Postgres :: is_closed=

Is the connection closed?
fun is_valid: Bool

postgresql :: Postgres :: is_valid

The status of this connection
init open(conninfo: Text)

postgresql :: Postgres :: open

Open the connnection with the database using the conninfo
fun prepare(stmt_name: String, query: String, num_params: Int): PGResult

postgresql :: Postgres :: prepare

Prepares the statement query with stmt_name to be executed later
fun raw_execute(query: Text): PGResult

postgresql :: Postgres :: raw_execute

Executes a query and returns the raw PGResult
fun replace(rest: Text): Bool

postgresql :: Postgres :: replace

Replace in the DB with a statement beginning with "REPLACE", followed by rest
fun reset

postgresql :: Postgres :: reset

Resets the connection to the database

Redefined properties

redef type SELF: Postgres

postgresql $ Postgres :: SELF

Type of this instance, automatically specialized in every class

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
fun create_table(rest: Text): Bool

postgresql :: Postgres :: create_table

Create a table on the DB with a statement beginning with "CREATE TABLE ", followed by rest
init defaultinit(native_connection: NativePostgres)

postgresql :: Postgres :: defaultinit

fun error: String

postgresql :: Postgres :: error

The latest error message on the connection an empty string if none
fun exec_prepared(stmt_name: String, num_params: Int, values: Array[String], param_lengths: Array[Int], param_formats: Array[Int], result_format: Int): PGResult

postgresql :: Postgres :: exec_prepared

Execute prepared statement named stmt_name with values
fun execute(query: Text): Bool

postgresql :: Postgres :: execute

Execute the sql statement and returns true on success
fun finish

postgresql :: Postgres :: finish

Close this connection with the database
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun hash: Int

core :: Object :: hash

The hash code of the object.
init init

core :: Object :: init

fun insert(rest: Text): Bool

postgresql :: Postgres :: insert

Insert in the DB with a statement beginning with "INSERT ", followed by rest
fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
fun is_closed: Bool

postgresql :: Postgres :: is_closed

Is the connection closed?
protected fun is_closed=(is_closed: Bool)

postgresql :: Postgres :: is_closed=

Is the connection closed?
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
fun is_valid: Bool

postgresql :: Postgres :: is_valid

The status of this connection
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
init open(conninfo: Text)

postgresql :: Postgres :: open

Open the connnection with the database using the conninfo
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun prepare(stmt_name: String, query: String, num_params: Int): PGResult

postgresql :: Postgres :: prepare

Prepares the statement query with stmt_name to be executed later
fun raw_execute(query: Text): PGResult

postgresql :: Postgres :: raw_execute

Executes a query and returns the raw PGResult
fun replace(rest: Text): Bool

postgresql :: Postgres :: replace

Replace in the DB with a statement beginning with "REPLACE", followed by rest
fun reset

postgresql :: Postgres :: reset

Resets the connection to the database
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
package_diagram postgresql::Postgres Postgres core::Object Object postgresql::Postgres->core::Object

Parents

interface Object

core :: Object

The root of the class hierarchy.

Class definitions

postgresql $ Postgres
# 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