Skip to content

Commit

Permalink
Merge pull request #3 from inf3cti0n95/rxjs6
Browse files Browse the repository at this point in the history
Upgraded to RxJS 6
  • Loading branch information
inf3cti0n95 authored Jun 18, 2018
2 parents 9596c87 + c2680d7 commit d82cff7
Show file tree
Hide file tree
Showing 6 changed files with 5,234 additions and 88 deletions.
33 changes: 19 additions & 14 deletions README.md
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!")
);
```
8 changes: 4 additions & 4 deletions lib/rx-sql.d.ts
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;
}
7 changes: 4 additions & 3 deletions lib/rx-sql.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/rx-sql.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 20 additions & 20 deletions src/rx-sql.ts
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();
}
}
Loading

0 comments on commit d82cff7

Please sign in to comment.