postgresql :: Postgres :: create_table
Create a table on the DB with a statement beginning with "CREATE TABLE ", followed byrest
postgresql :: Postgres :: defaultinit
postgresql :: Postgres :: error
The latest error message on the connection an empty string if nonepostgresql :: Postgres :: exec_prepared
Execute prepared statement namedstmt_name
with values
postgresql :: Postgres :: is_closed=
Is the connection closed?postgresql :: Postgres :: open
Open the connnection with the database using theconninfo
postgresql :: Postgres :: raw_execute
Executes aquery
and returns the raw PGResult
postgresql $ Postgres :: SELF
Type of this instance, automatically specialized in every classcore :: Object :: class_factory
Implementation used byget_class
to create the specific class.
postgresql :: Postgres :: create_table
Create a table on the DB with a statement beginning with "CREATE TABLE ", followed byrest
postgresql :: Postgres :: defaultinit
core :: Object :: defaultinit
postgresql :: Postgres :: error
The latest error message on the connection an empty string if nonepostgresql :: Postgres :: exec_prepared
Execute prepared statement namedstmt_name
with values
postgresql :: Postgres :: is_closed=
Is the connection closed?core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
postgresql :: Postgres :: open
Open the connnection with the database using theconninfo
core :: Object :: output_class_name
Display class name on stdout (debug only).postgresql :: Postgres :: raw_execute
Executes aquery
and returns the raw PGResult
# 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