Module: Postgres-StORM
extension PostgresStORM
func delete() throws
Deletes one row, with an id.
Presumes first property in class is the id.
func delete(_ id: Any) throws
Deletes one row, with the id as set.
func get(_ id: Any) throws
Retrieves a single row with the supplied ID.
func get() throws
Retrieves a single row with the ID as set.
func find(_ data: [(String, Any)]) throws
Performs a find on mathing column name/value pairs.
func find(_ data: [String: Any]) throws
Performs a find on mathing column name/value pairs.
extension PostgresStORM
func insert(_ data: [(String, Any)]) throws -> Any
Insert function where the suppled data is in [(String, Any)] format.
func insert(_ data: [String: Any]) throws -> Any
Insert function where the suppled data is in [String: Any] format.
func insert(cols: [String], params: [Any]) throws -> Any
Insert function where the suppled data is in matching arrays of columns and parameter values.
func insert(cols: [String], params: [Any], idcolumn: String) throws -> Any
Insert function where the suppled data is in matching arrays of columns and parameter values, as well as specifying the name of the id column.
func PostgresMap(_ i: Int) -> String
This is a reference function used to help the ORM class determine how to interpret field types from Postgres.
The function is not meant for use outside this library.
struct PostgresConnector
PostgresConnector sets the connection parameters for the PostgreSQL Server access
Usage:
PostgresConnector.host = "XXXXXX"
PostgresConnector.username = "XXXXXX"
PostgresConnector.password = "XXXXXX"
PostgresConnector.port = 5432
extension PostgresStORM
func findAll() throws
Retrieves all rows in the table, only limited by the cursor (9,999,999 rows)
func select(
whereclause: String,
params: [Any],
orderby: [String],
cursor: StORMCursor = StORMCursor(),
joins: [StORMDataSourceJoin] = [],
having: [String] = [],
groupBy: [String] = []
) throws
Select function with specific where clause.
Parameterized statements are used, so all params should be passed in using the [Any] params array.
The whereclause should be specified in the following format: "name = $1 AND email LIKE $2"
An orderby array can be specified in a String array like ["name DESC","email ASC"]
A StORMCursor can be supplied, otherwise the default values are used.
Note that the joins, having and groupBy functionality is unimplemented at this time.
The select function will populate the object with the results of the query.
func select(
columns: [String],
whereclause: String,
params: [Any],
orderby: [String],
cursor: StORMCursor = StORMCursor(),
joins: [StORMDataSourceJoin] = [],
having: [String] = [],
groupBy: [String] = []
) throws
Select function with specific where clause, and spefified columns to return.
Parameterized statements are used, so all params should be passed in using the [Any] params array.
The whereclause should be specified in the following format: "name = $1 AND email LIKE $2"
An orderby array can be specified in a String array like ["name DESC","email ASC"]
A StORMCursor can be supplied, otherwise the default values are used.
Note that the joins, having and groupBy functionality is unimplemented at this time.
The select function will populate the object with the results of the query.
extension PostgresStORM
func sql(_ statement: String, params: [String]) throws -> PGResult
Execute Raw SQL (with parameter binding)
Returns PGResult (discardable)
func sqlRows(_ statement: String, params: [String]) throws -> [StORMRow]
Execute Raw SQL (with parameter binding)
Returns [StORMRow] (discardable)
extension PostgresStORM
func update(cols: [String], params: [Any], idName: String, idValue: Any) throws -> Bool
Updates the row with the specified data.
This is an alternative to the save() function.
Specify matching arrays of columns and parameters, as well as the id name and value.
func update(data: [(String, Any)], idName: String = "id", idValue: Any) throws -> Bool
Updates the row with the specified data.
This is an alternative to the save() function.
Specify a [(String, Any)] of columns and parameters, as well as the id name and value.
extension PostgresStORM
func upsert(cols: [String], params: [Any], conflictkeys: [String]) throws
Inserts the row with the specified data, on conflict (conflickkeys columns) it will perform an update.
Specify matching arrays of columns and parameters, and an array of conflict key columns.