Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Order by parameter support

  • Loading branch information...
commit 0e324719180fd032b80b8baa1f2b0b2d382fb148 1 parent 916fa29
@bjornharrtell authored
View
27 README.md
@@ -2,15 +2,13 @@
Attempt to implement something like the proposal at http://wiki.postgresql.org/wiki/HTTP_API
-**DISCLAIMER**: Experimental work at this time.
-
[![Build Status](https://secure.travis-ci.org/bjornharrtell/postgresql-http-server.png?branch=master)](http://travis-ci.org/bjornharrtell/postgresql-http-server)
## Installing
NOTE: Requires node.js
- # sudo npm install postgresql-http-server -g
+ # npm install postgresql-http-server
## Usage
@@ -18,13 +16,14 @@ NOTE: Requires node.js
PostgreSQL HTTP API Server
Options:
- --port HTTP Server port [required] [default: 3000]
- --dbhost PostgreSQL host [required] [default: "localhost"]
- --dbport PostgreSQL port [required] [default: 5432]
- --database PostgreSQL database [required] [default: <user>]
- --user PostgreSQL username [required] [default: <user>]
+ --port HTTP Server port [required] [default: 3000]
+ --dbhost PostgreSQL host [required] [default: "localhost"]
+ --dbport PostgreSQL port [required] [default: 5432]
+ --database PostgreSQL database [required] [default: <user>]
+ --user PostgreSQL username [required] [default: <user>]
--password PostgreSQL password
- --cors Enable CORS support [boolean]
+ --raw Enable raw SQL usage [boolean]
+ --cors Enable CORS support [boolean]
--help Show this message
## API Usage
@@ -40,14 +39,17 @@ do the following operations:
Retrieve rows (GET), update rows (PUT) or create a new row (POST) at:
/db/testdb/schemas/public/tables/testtable/rows
-The above resources accepts URL encoded parameters where, limit and offset
-where applicable. Example:
+The above resources accepts URL encoded parameters where, limit, offset
+and orderby where applicable. Example:
GET a maximum of 10 rows where cost>100 at:
/db/testdb/schemas/public/tables/testtable/rows?where=cost%3E100&limit=10
The default and currently the only dataformat is JSON. POSTing or PUTing
-expects a single JSON object with properties corresponding to column names.
+expects a JSON object with properties corresponding to column names.
+
+Raw SQL queries can be POSTed to the database resource. Expected data
+is a JSON object with the SQL string as property named "sql".
## TODOs
@@ -55,7 +57,6 @@ expects a single JSON object with properties corresponding to column names.
* Stream row data
* Configurable max rows hard limit
* Optionally use authenticated user/password to connect to DB
-* Handle ORDER BY via orderby param
* Handle PostGIS data
## License
View
4 lib/db.coffee
@@ -54,6 +54,9 @@ module.exports = (log, connectionString, database) ->
config.sql += " OFFSET $#{config.count}"
config.values.push parseInt offset
config.count += 1
+
+ parseOrderBy = (config, orderby) -> if orderby
+ config.sql += " ORDER BY #{orderby}"
parseRow = (row) ->
fields = []
@@ -75,5 +78,6 @@ module.exports = (log, connectionString, database) ->
parseWhere: parseWhere
parseLimit: parseLimit
parseOffset: parseOffset
+ parseOrderBy: parseOrderBy
parseRow: parseRow
View
1  lib/resources/rows.coffee
@@ -23,6 +23,7 @@ module.exports = (server) ->
db.parseWhere config, req.query.where
db.parseLimit config, req.query.limit
db.parseOffset config, req.query.offset
+ db.parseOrderBy config, req.query.orderby
db.query config
View
7 package.json
@@ -1,6 +1,6 @@
{
"name": "postgresql-http-server",
- "version": "0.4.0",
+ "version": "0.5.0",
"author": "Björn Harrtell <bjorn@wololo.org>",
"description": "PostgreSQL HTTP API Server",
"homepage": "https://github.com/bjornharrtell/postgresql-http-server",
@@ -9,7 +9,6 @@
"scripts": {
"test": "mocha --recursive --require coffee-script --reporter dot test/specs/**/*"
},
- "preferGlobal": "true",
"repository": {
"type": "git",
"url": "https://github.com/bjornharrtell/postgresql-http-server.git"
@@ -24,9 +23,9 @@
"coffee-script": "1.3.3",
"optimist": "0.3.4",
"express": "2.5.11",
- "pg": "0.7.2",
+ "pg": "0.8.4",
"log": "1.3.0",
- "mocha": "1.3.0"
+ "mocha": "1.4.2"
},
"license": "MIT"
}
Please sign in to comment.
Something went wrong with that request. Please try again.