-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from inf3cti0n95/rxjs6
Upgraded to RxJS 6
- Loading branch information
Showing
6 changed files
with
5,234 additions
and
88 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,29 @@ | ||
# rx-sql | ||
|
||
[![Build Status](https://travis-ci.org/inf3cti0n95/rx-sql.svg?branch=master)](https://travis-ci.org/inf3cti0n95/rx-sql) | ||
|
||
RxJS Implementation of MySQL | ||
|
||
``` | ||
```js | ||
import { RxSQL } from "rx-sql"; | ||
import { createConnection } from "mysql"; | ||
import { flatMap } from "rxjs/operators"; | ||
|
||
db = createConnection({ | ||
host: localhost, | ||
database: test, | ||
user: root, | ||
password: "" | ||
let db = createConnection({ | ||
host: "localhost", | ||
database: "database", | ||
user: "root", | ||
password: "password" | ||
}); | ||
|
||
let rxsql$ = new RxSQL(db); | ||
|
||
rxsql$.query("SELECT * FROM TESTTABLE") | ||
.flatMap(result => result.col1) | ||
.subscribe( | ||
result => console.log(result), | ||
error => console.log(error) | ||
); | ||
``` | ||
rxsql$ | ||
.query("SELECT * FROM table") | ||
.pipe(flatMap(result => result)) | ||
.subscribe( | ||
result => console.log(result), | ||
error => console.error(error) | ||
() => console.info("Completed!") | ||
); | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { IConnection } from "mysql"; | ||
import { Connection, QueryOptions } from "mysql"; | ||
import { Observable } from "rxjs"; | ||
export declare class RxSQL { | ||
connection: IConnection; | ||
constructor(connectionParam: IConnection); | ||
query<T>(query: string): Observable<T>; | ||
connection: Connection; | ||
constructor(connectionParam: Connection); | ||
query<T>(query: string | QueryOptions): Observable<T>; | ||
destroyConnection(): void; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
import { createConnection, IConnection, IQuery, IConnectionConfig } from "mysql"; | ||
import { Connection, QueryOptions } from "mysql"; | ||
import { Observable, Observer } from "rxjs"; | ||
|
||
export class RxSQL { | ||
public connection: IConnection; | ||
constructor(connectionParam: IConnection) { | ||
this.connection = connectionParam; | ||
} | ||
public connection: Connection; | ||
constructor(connectionParam: Connection) { | ||
this.connection = connectionParam; | ||
} | ||
|
||
public query<T>(query: string): Observable<T>{ | ||
return Observable.create((observer: Observer<T>) => { | ||
this.connection.query(query,(error, result, fields) => { | ||
if(error) | ||
observer.error(error) | ||
else | ||
observer.next(result) | ||
observer.complete(); | ||
}) | ||
}) | ||
} | ||
public query<T>(query: string | QueryOptions): Observable<T> { | ||
return Observable.create((observer: Observer<T>) => { | ||
this.connection.query(query, (error, result) => { | ||
if (error) observer.error(error); | ||
else { | ||
observer.next(result); | ||
} | ||
observer.complete(); | ||
}); | ||
}); | ||
} | ||
|
||
public destroyConnection(){ | ||
this.connection.destroy(); | ||
} | ||
} | ||
public destroyConnection() { | ||
this.connection.destroy(); | ||
} | ||
} |
Oops, something went wrong.