Skip to content

Commit

Permalink
last changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed Apr 24, 2016
1 parent 9304343 commit 0254732
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 31 deletions.
7 changes: 5 additions & 2 deletions lib/errors/prepared.js
Expand Up @@ -16,15 +16,18 @@ var $npm = {
*
* The type is available from the {@link errors} namespace.
*
* @property {string} name
* Standard {@link external:Error Error} property - error type name = `PreparedStatementError`.
*
* @property {string} message
* Standard {@link external:Error Error} property - the error message.
*
* @property {object} stack
* Standard {@link external:Error Error} property - the stack trace.
*
* @property {QueryFileError} error
* Internal {@link QueryFileError} object.
*
* Internal {@link QueryFileError} object.
*
* It is set only when the source {@link PreparedStatement} used a {@link QueryFile} which threw the error.
*
* @returns {PreparedStatementError}
Expand Down
7 changes: 5 additions & 2 deletions lib/errors/queryFile.js
Expand Up @@ -15,6 +15,9 @@ var $npm = {
*
* The type is available from the {@link errors} namespace.
*
* @property {string} name
* Standard {@link external:Error Error} property - error type name = `QueryFileError`.
*
* @property {string} message
* Standard {@link external:Error Error} property - the error message.
*
Expand All @@ -29,8 +32,8 @@ var $npm = {
*
* @property {SQLParsingError} error
* Internal $[SQLParsingError] object.
*
* It is set only when the error was thrown by $[pg-minify] while trying parse the SQL file.
*
* It is set only when the error was thrown by $[pg-minify] while parsing the SQL file.
*
* @returns {QueryFileError}
*/
Expand Down
3 changes: 3 additions & 0 deletions lib/errors/queryResult.js
Expand Up @@ -60,6 +60,9 @@ var errorMessages = [
*
* The type is available from the {@link errors} namespace.
*
* @property {string} name
* Standard {@link external:Error Error} property - error type name = `QueryResultError`.
*
* @property {string} message
* Standard {@link external:Error Error} property - the error message.
*
Expand Down
3 changes: 3 additions & 0 deletions lib/prepared.js
Expand Up @@ -41,6 +41,9 @@ var $npm = {
* @property {Array} values
* Query formatting values. It can be either an `Array` or `null`/`undefined`.
*
* @property {PreparedStatementError} error
* Set to a {@link PreparedStatementError} object, but only when in error state.
*
* @returns {PreparedStatement}
*
* @see {@link http://www.postgresql.org/docs/9.5/static/sql-prepare.html PostgreSQL Prepared Statements}
Expand Down
4 changes: 2 additions & 2 deletions lib/queryFile.js
Expand Up @@ -217,10 +217,10 @@ function QueryFile(file, options) {
return sql;
}
});

/**
* @name QueryFile#error
* @type Error
* @type {QueryFileError}
* @default undefined
* @readonly
* @description
Expand Down
1 change: 1 addition & 0 deletions test/typescript/build.bat
Expand Up @@ -11,3 +11,4 @@ call tsc extensions %PARAMS%
call tsc minify %PARAMS%
call tsc pg %PARAMS%
call tsc prepared %PARAMS%
call tsc errors %PARAMS%
14 changes: 14 additions & 0 deletions test/typescript/errors.ts
@@ -0,0 +1,14 @@
/// <reference path='../../typescript/pg-promise' />

import * as pgPromise from 'pg-promise';

var result = new pgPromise.errors.QueryResultError();
var resultCheck = result instanceof pgPromise.errors.QueryResultError;

var query = new pgPromise.errors.QueryFileError();
var queryCheck = result instanceof pgPromise.errors.QueryFileError;
var line = query.error.position.line;

var ps = new pgPromise.errors.PreparedStatementError();
var queryCheck = result instanceof pgPromise.errors.PreparedStatementError;
var file = ps.error.file;
3 changes: 3 additions & 0 deletions test/typescript/prepared.ts
Expand Up @@ -9,6 +9,9 @@ var ps1 = new pgp.PreparedStatement('', '', []);
var ps2 = new pgp.PreparedStatement({name: '', text: ''});
var ps3 = new pgp.PreparedStatement(ps1);

var qf = new pgPromise.QueryFile('file');
var ps4 = new pgp.PreparedStatement({name: '', text: qf});

db.one(ps1.get());
db.one(ps1);

Expand Down
77 changes: 52 additions & 25 deletions typescript/pg-promise.d.ts
@@ -1,5 +1,5 @@
////////////////////////////////////////
// Requires pg-promise v3.9.0 or later.
// Requires pg-promise v4.0.0 or later.
////////////////////////////////////////

/// <reference path='./pg-subset' />
Expand All @@ -12,8 +12,10 @@ declare module 'pg-promise' {
import * as pgMinify from 'pg-minify';
import XPromise = require('ext-promise'); // External Promise Provider

type TQueryFileOptions= {debug?:boolean, minify?:boolean|'after', compress?:boolean, params?:any};
type TFormattingOptions = {partial?:boolean};
type TPrepared = {name:string, text:string, values?:Array<any>};
type TPreparedBasic = {name:string, text:string, values?:Array<any>};
type TPrepared = {name:string, text:string|pgPromise.QueryFile, values?:Array<any>};
type TQuery = string|pgPromise.QueryFile|TPrepared|pgPromise.PreparedStatement;

// Base database protocol
Expand Down Expand Up @@ -204,7 +206,41 @@ declare module 'pg-promise' {
values:any;

// API: http://vitaly-t.github.io/pg-promise/QueryResultError.html#.toString
toString():string;
toString(level?:number):string;
}

// QueryFileError class;
// API: http://vitaly-t.github.io/pg-promise/QueryFileError.html
class QueryFileError implements Error {

// standard error properties:
name:string;
message:string;
stack:string;

// extended properties:
file:string;
options:TQueryFileOptions;
error:pgMinify.SQLParsingError;

// API: http://vitaly-t.github.io/pg-promise/QueryFileError.html#.toString
toString(level?:number):string;
}

// PreparedStatementError class;
// API: http://vitaly-t.github.io/pg-promise/PreparedStatementError.html
class PreparedStatementError implements Error {

// standard error properties:
name:string;
message:string;
stack:string;

// extended properties:
error:QueryFileError;

// API: http://vitaly-t.github.io/pg-promise/PreparedStatementError.html#.toString
toString(level?:number):string;
}

// Query Result Error Code;
Expand All @@ -220,6 +256,8 @@ declare module 'pg-promise' {
interface IErrors {
QueryResultError:typeof QueryResultError;
queryResultErrorCode:typeof queryResultErrorCode;
QueryFileError:typeof QueryFileError;
PreparedStatementError:typeof PreparedStatementError;
}

// Transaction Mode namespace;
Expand Down Expand Up @@ -264,43 +302,32 @@ declare module 'pg-promise' {
none = 4,
any = 6
}

// PreparedStatement class;
// API: http://vitaly-t.github.io/pg-promise/PreparedStatement.html
class PreparedStatement {

// API: http://vitaly-t.github.io/pg-promise/PreparedStatement.html
constructor(name:string, text:string, values?:Array<any>);
constructor(name:string, text:string|QueryFile, values?:Array<any>);
constructor(obj:TPrepared);

name:string;
text:string;
values:Array<any>;

// API: http://vitaly-t.github.io/pg-promise/PreparedStatement.html#.get
get():TPrepared;

// API: http://vitaly-t.github.io/pg-promise/PreparedStatement.html#.create
create(values?:Array<any>):TPrepared;

// API: http://vitaly-t.github.io/pg-promise/PreparedStatement.html#.format
format(options?:TFormattingOptions):string;


// API: http://vitaly-t.github.io/pg-promise/PreparedStatement.html#.parse
parse():TPreparedBasic|PreparedStatementError;

// API: http://vitaly-t.github.io/pg-promise/PreparedStatement.html#.toString
toString():string;
toString(level?:number):string;
}

// QueryFile class;
// API: http://vitaly-t.github.io/pg-promise/QueryFile.html
class QueryFile {

// API: http://vitaly-t.github.io/pg-promise/QueryFile.html
constructor(file:string, options?:{
debug?:boolean,
minify?:boolean|'after',
compress?:boolean,
params?:any
});
constructor(file:string, options?:TQueryFileOptions);

// API: http://vitaly-t.github.io/pg-promise/QueryFile.html#error
error:Error;
Expand All @@ -318,7 +345,7 @@ declare module 'pg-promise' {
prepare():void;

// API: http://vitaly-t.github.io/pg-promise/QueryFile.html#.toString
toString():string;
toString(level?:number):string;
}

// PromiseAdapter class;
Expand Down

0 comments on commit 0254732

Please sign in to comment.