# ngx-mysql

> Project ini adalah modul Angular 2 yang berfungsi untuk memudahkan integrasi antara angular 2, electron dan database mysql.

Latest version **1.1.1** (published 2018-05-12) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install ngx-mysql
pnpm add ngx-mysql
yarn add ngx-mysql
bun add ngx-mysql
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2018-05-12 |
| First published | 2018-05-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 69.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | mochrira |

## Links

- npm: https://www.npmjs.com/package/ngx-mysql
- npm.io page: https://npm.io/package/ngx-mysql

## Dependencies (2)

- [mysql](https://npm.io/package/mysql.md) ^2.15.0
- [tslib](https://npm.io/package/tslib.md) ^1.9.0

## Recent versions

- 1.1.1 (latest) — 2018-05-12
- 1.1.0 — 2018-05-11
- 1.0.1 — 2018-05-10

## README

# NgxMysql

Project ini adalah modul Angular 2 yang berfungsi untuk memudahkan integrasi antara angular 2, electron dan database mysql.

## Pendahuluan

Modul ini mengintegrasikan library [mysql](https://github.com/mysqljs/mysql) dengan [Angular 2](https://github.com/angular/angular) + [Electron](https://github.com/electron/electron). Sebelumnya saya asumsikan anda sudah berhasil mengintegrasikan Angular dengan Electron. Jika belum anda dapat mengikuti tutorial berikut [Membuat aplikasi desktop dengan Angular dan Electron](http://blog.wajek.id/2018/05/05/membuat-aplikasi-desktop-dengan-angular-5-dan-electron/). Berikut adalah contoh bagaimana menggunakan modul ini : 

Langkah 1. Deklarasikan variable `remote` pada src/index.html

```
<html>
    <head>
        <title>Angular 2 App</title>
    </head>
    <body>
        <app-root></app-root>
        <script>
            var remote = require('electron').remote();
        </script>
    </body>
</html>
```

Langkah 2. Buka app.module.ts dan deklarasikan remote sebagai variable global Angular

```
import { NgxElectronMysqlModule } from 'ngx-electron-mysql';

//another imports
import {...} from ...

declare var remote : any;

@NgModule({
    declarations : [...]
    imports : [
        NgxElectronMysqlModule.forRoot(remote)
    ],
    providers : [...]
})

export class AppModule {}
```

Langkah 3. Buka app.component.ts

```
import { Component } from '@angular/core';
import { Mysql } from '../../lib';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  constructor(
    private mysql : Mysql
  ){
    this.mysql.open({
      host : '127.0.0.1',
      user : 'root',
      password : '',
      database : 'test'
    }).then(res => {
      this.mysql.query('SELECT*FROM users').then(res => {
        console.log(res);
      })
    })
  }
}

```

## result
result(nama_tabel) digunakan untuk mendapatkan baris lebih dari satu

```
this.mysql.result('users').then(res => {
  console.log(res);
});
```

## row
row(nama_tabel) digunakan untuk mendapatkan satu baris berdasarkan filter yang diterapkan

```
this.mysql.row('users').then(res => {
  console.log(res); 
})
```

## where
where(filter) digunakan untuk menyaring hasil sebelum memanggil row atau result

```
this.mysql.where({ id_user : 1 }).then(res => {
  this.mysql.row('users').then(res => {
    console.log(res); 
  })
});
```

## select
select(column_string) digunakan untuk memilih field mana saja untuk ditampilkan

```
this.mysql.where({ id_user : 1 }).then(res => {
  this.mysql.select('id_user, nm_user').then(res => {
    this.mysql.row('users').then(res => {
      console.log(res); 
    })
  })
});
```

## inner_join
inner_join(nama_tabel, relasi) digunakan untuk mendapatkan hasil join dari 2 tabel

```
this.mysql.inner_join('activities', 'activities.id_user = users.id_user').then(res => {
  this.mysql.result('users').then(res => {
    console.log(res);
  })
})
```

## insert
insert(nama_tabel, data) digunakan untuk menambahkan data pada tabel

```
this.mysql.insert('users',{
  nm_pengguna : this.nm_pengguna,
  username : this.username
}).then(res => {
  console.log(res);
})
```

## update
update(nama_tabel, data) digunakan untuk mengupdate data pada tabel

```
this.mysql.where({id_user : 1}).then(res => {
  this.mysql.update('users',{
    nm_pengguna : this.nm_pengguna,
    username : this.username
  }).then(res => {
    console.log(res);
  })
})
```

## delete
delete(nama_tabel) digunakan untuk menghapus data pada tabel

```
this.mysql.where({id_user : 1}).then(res => {
  this.mysql.delete('users').then(res => {
    console.log(res);
  })
})
```

## Berkontribusi

Anda dapat mengkontribusi dengan mengkloning project ini dan menjalankan perintah 

```
npm install
```

selanjutnya ketikkan perintah berikut untuk menjalankan aplikasi testing

```
terminal> ng build --watch
terminal> electron main
```

---
_Source: https://npm.io/package/ngx-mysql · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
