Skip to content

Instantly share code, notes, and snippets.

@rafagsiqueira
Created January 16, 2021 16:12
Show Gist options
  • Save rafagsiqueira/d51363476400521eeba61c4d7ec005e4 to your computer and use it in GitHub Desktop.
Save rafagsiqueira/d51363476400521eeba61c4d7ec005e4 to your computer and use it in GitHub Desktop.
Example mssql query to observable stream
import { ConnectionPool } from 'mssql';
export class DatabaseClient {
pool: ConnectionPool;
dbConfig: {redated};
constructor() {
super();
this.pool = new ConnectionPool(this.dbConfig);
}
getUsers$ = (): Observable<any> => from(this.pool.connect()).pipe(
switchMap(() => {
const request = this.pool.request();
return from(request.query("SELECT email, name FROM users")).pipe(
pluck('recordset'),
mergeAll()
);
})
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment