Created
January 16, 2021 16:12
-
-
Save rafagsiqueira/d51363476400521eeba61c4d7ec005e4 to your computer and use it in GitHub Desktop.
Example mssql query to observable stream
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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