Skip to content
Browse files

Correct err handling and tabs in samples

  • Loading branch information...
1 parent ea15671 commit 81e7d9a7cf38b1ffc75f980985af24f6d0abf357 @wdavidw committed Dec 6, 2011
Showing with 51 additions and 36 deletions.
  1. +35 −28 README.md
  2. +3 −1 samples/pipe.coffee
  3. +2 −1 samples/query.coffee
  4. +6 −3 samples/style_native.js
  5. +5 −3 samples/style_sugar.js
View
63 README.md
@@ -12,25 +12,27 @@ npm install thrift-hive
## Quick example
```javascript
-var assert = require('assert');
var hive = require('thrift-hive');
// Client connection
var client = hive.createClient({
- version: '0.7.1-cdh3u2',
- server: '127.0.0.1',
- port: 10000,
- timeout: 1000
+ version: '0.7.1-cdh3u2',
+ server: '127.0.0.1',
+ port: 10000,
+ timeout: 1000
});
// Execute query
client.execute('use default', function(err){
- client.query('show tables')
- .on('row', function(database){
- console.log(database);
- })
- .on('end', function(err){
- assert.ifError(err);
- client.end();
- });
+ client.query('show tables')
+ .on('row', function(database){
+ console.log(database);
+ })
+ .on('error', function(err){
+ console.log(err.message);
+ client.end();
+ });
+ .on('end', function(){
+ client.end();
+ });
});
```
@@ -71,14 +73,14 @@ Available API
hive = require 'thrift-hive'
# Client connection
client = hive.createClient
- version: '0.7.1-cdh3u2'
- server: '127.0.0.1'
- port: 10000
- timeout: 1000
+ version: '0.7.1-cdh3u2'
+ server: '127.0.0.1'
+ port: 10000
+ timeout: 1000
# Execute
client.execute 'USE default', (err) ->
- console.log err.message if err
- client.end()
+ console.log err.message if err
+ client.end()
```
## Hive Query
@@ -126,7 +128,9 @@ client = hive.createClient
client.query('show tables')
.on 'row', (database) ->
this.emit 'data', 'Found ' + database + '\n'
-.on 'end', (err) ->
+.on 'error', (err) ->
+ client.end()
+.on 'end', () ->
client.end()
.pipe( fs.createWriteStream "#{__dirname}/pipe.out" )
```
@@ -147,14 +151,17 @@ var connection = thrift.createConnection('127.0.0.1', 10000, options);
var client = thrift.createClient(ThriftHive, connection);
// Execute query
client.execute('use default', function(err){
- client.execute('show tables', function(err){
- assert.ifError(err);
- client.fetchAll(function(err, databases){
- assert.ifError(err);
- console.log(databases);
- connection.end();
- });
- });
+ client.execute('show tables', function(err){
+ assert.ifError(err);
+ client.fetchAll(function(err, databases){
+ if(err){
+ console.log(err.message);
+ }else{
+ console.log(databases);
+ }
+ connection.end();
+ });
+ });
});
```
View
4 samples/pipe.coffee
@@ -12,6 +12,8 @@ client = hive.createClient
client.query('show tables')
.on 'row', (database) ->
this.emit 'data', 'Found ' + database + '\n'
-.on 'end', (err) ->
+.on 'error', (err) ->
+ client.end()
+.on 'end', () ->
client.end()
.pipe( fs.createWriteStream "#{__dirname}/pipe.out" )
View
3 samples/query.coffee
@@ -14,7 +14,8 @@ client.execute 'use test_database', (err) ->
console.log row
query.resume()
, 100
- .on 'end', (err) ->
+ .on 'error', (err) ->
+ .on 'end', () ->
console.log err.message if err
client.end()
View
9 samples/style_native.js
@@ -13,9 +13,12 @@ client.execute('use default', function(err){
client.execute('show tables', function(err){
assert.ifError(err);
client.fetchAll(function(err, databases){
- assert.ifError(err);
- console.log(databases);
+ if(err){
+ console.log(err.message);
+ }else{
+ console.log(databases);
+ }
connection.end();
});
});
-});
+});
View
8 samples/style_sugar.js
@@ -1,6 +1,5 @@
#!/usr/bin/env node
-var assert = require('assert');
var hive = require('thrift-hive');
// Client connection
var client = hive.createClient({
@@ -15,8 +14,11 @@ client.execute('use default', function(err){
.on('row', function(database){
console.log(database);
})
- .on('end', function(err){
- assert.ifError(err);
+ .on('error', function(err){
+ console.log(err.message);
+ client.end();
+ });
+ .on('end', function(){
client.end();
});
});

0 comments on commit 81e7d9a

Please sign in to comment.
Something went wrong with that request. Please try again.