json-db-engine 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +64 -0
- package/CONTRIBUTING.md +127 -0
- package/LICENSE +21 -0
- package/README.md +303 -0
- package/add.js +10 -0
- package/delete.js +8 -0
- package/example.js +76 -0
- package/find.js +8 -0
- package/load.js +10 -0
- package/main.js +30 -0
- package/module.js +5 -0
- package/package.json +39 -0
- package/read.js +8 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
Semua perubahan penting pada project ini akan didokumentasikan di file ini.
|
|
4
|
+
|
|
5
|
+
Format yang digunakan mengikuti [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) dan versioning mengikuti [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
## [1.0.0] - 2026-02-09
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
- ✨ Implementasi Database Class dengan CRUD operations lengkap
|
|
11
|
+
- 📖 READ operation - membaca semua data dari file JSON
|
|
12
|
+
- ➕ CREATE operation - menambah data baru ke database
|
|
13
|
+
- 🔍 FIND operation - mencari data berdasarkan property dan value
|
|
14
|
+
- 🗑️ DELETE operation - menghapus data berdasarkan property dan value
|
|
15
|
+
- 📁 Struktur modular dengan pemisahan logic menjadi functions terpisah
|
|
16
|
+
- 📚 Dokumentasi lengkap dalam README.md
|
|
17
|
+
- 🔧 Package.json dengan script dan metadata lengkap
|
|
18
|
+
- 📜 MIT License
|
|
19
|
+
- 🤝 CONTRIBUTING.md untuk kontributor
|
|
20
|
+
- 🎯 Example.js dengan demonstrasi lengkap semua operasi
|
|
21
|
+
|
|
22
|
+
### What's Inside
|
|
23
|
+
- `module.js` - Wrapper untuk Node.js fs module
|
|
24
|
+
- `load.js` - Load dan parse data dari file JSON
|
|
25
|
+
- `read.js` - Read data dengan parsing
|
|
26
|
+
- `add.js` - Add/create data baru
|
|
27
|
+
- `find.js` - Find/search data
|
|
28
|
+
- `delete.js` - Delete data
|
|
29
|
+
- `main.js` - Database class (orchestrator)
|
|
30
|
+
- `example.js` - Complete demonstration
|
|
31
|
+
|
|
32
|
+
### Learning Outcomes
|
|
33
|
+
- ✅ Object-Oriented Programming dengan JavaScript Class
|
|
34
|
+
- ✅ Node.js File System operations
|
|
35
|
+
- ✅ JSON parsing dan stringifying
|
|
36
|
+
- ✅ Array methods: push, filter, find
|
|
37
|
+
- ✅ ES6 Modules (import/export)
|
|
38
|
+
- ✅ Information architecture dan modular code
|
|
39
|
+
- ✅ Git & GitHub basics
|
|
40
|
+
- ✅ Creating documentation
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Rencana Versi Berikutnya
|
|
45
|
+
|
|
46
|
+
### [1.1.0] - Planned
|
|
47
|
+
- [ ] Async/await version untuk non-blocking operations
|
|
48
|
+
- [ ] Update operation untuk edit data existing
|
|
49
|
+
- [ ] Input validation dan error handling yang lebih robust
|
|
50
|
+
- [ ] Schema validation sebelum menyimpan data
|
|
51
|
+
- [ ] Support untuk multiple file types (CSV, XML)
|
|
52
|
+
- [ ] Unit tests dengan Jest
|
|
53
|
+
|
|
54
|
+
### [2.0.0] - Future Vision
|
|
55
|
+
- [ ] CLI interface untuk interactive database management
|
|
56
|
+
- [ ] Web API dengan Express.js
|
|
57
|
+
- [ ] User authentication & authorization
|
|
58
|
+
- [ ] Database encryption
|
|
59
|
+
- [ ] Performance optimization & caching
|
|
60
|
+
- [ ] Database indexing
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
**Terima kasih telah menggunakan LearnJS!** 🚀
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# Panduan Kontribusi
|
|
2
|
+
|
|
3
|
+
Terima kasih telah tertarik untuk berkontribusi pada project **LearnJS**! 🎉
|
|
4
|
+
|
|
5
|
+
## Bagaimana Cara Berkontribusi?
|
|
6
|
+
|
|
7
|
+
### 1. Fork Repository
|
|
8
|
+
```bash
|
|
9
|
+
# Clone repository Anda
|
|
10
|
+
git clone https://github.com/wa130/json-db-enginee.git
|
|
11
|
+
cd json-db-enginee
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
### 2. Buat Branch Baru
|
|
15
|
+
```bash
|
|
16
|
+
git checkout -b feature/nama-fitur
|
|
17
|
+
# atau
|
|
18
|
+
git checkout -b fix/nama-bug
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### 3. Lakukan Perubahan
|
|
22
|
+
- Pastikan kode Anda clean dan terstruktur dengan baik
|
|
23
|
+
- Ikuti style guide yang ada di project
|
|
24
|
+
- Tambahkan komentar untuk kode yang kompleks
|
|
25
|
+
|
|
26
|
+
### 4. Test Perubahan Anda
|
|
27
|
+
```bash
|
|
28
|
+
node example.js
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### 5. Commit Perubahan
|
|
32
|
+
```bash
|
|
33
|
+
git add .
|
|
34
|
+
git commit -m "feat: deskripsi singkat perubahan"
|
|
35
|
+
# atau
|
|
36
|
+
git commit -m "fix: deskripsi singkat perbaikan"
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### 6. Push ke Repository Anda
|
|
40
|
+
```bash
|
|
41
|
+
git push origin feature/nama-fitur
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 7. Buat Pull Request
|
|
45
|
+
- Buka repository Anda di GitHub
|
|
46
|
+
- Klik tombol "Pull Request"
|
|
47
|
+
- Jelaskan perubahan yang Anda buat
|
|
48
|
+
- Tunggu review dari maintainer
|
|
49
|
+
|
|
50
|
+
## Style Guide
|
|
51
|
+
|
|
52
|
+
### JavaScript
|
|
53
|
+
- Gunakan `camelCase` untuk variable dan function
|
|
54
|
+
- Gunakan `PascalCase` untuk class
|
|
55
|
+
- Gunakan arrow functions untuk callbacks
|
|
56
|
+
- Tambahkan JSDoc comments untuk functions yang kompleks
|
|
57
|
+
|
|
58
|
+
### Contoh:
|
|
59
|
+
```javascript
|
|
60
|
+
/**
|
|
61
|
+
* Mencari data di database
|
|
62
|
+
* @param {string} path - Path ke file database
|
|
63
|
+
* @param {string} property - Property yang dicari
|
|
64
|
+
* @param {*} value - Value yang dicari
|
|
65
|
+
* @returns {object} - Data yang ditemukan
|
|
66
|
+
*/
|
|
67
|
+
export default function find(path, property, value) {
|
|
68
|
+
const database = load(path)
|
|
69
|
+
return database.find((item) => item[property] === value)
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Jenis Kontribusi yang Diharapkan
|
|
74
|
+
|
|
75
|
+
### Bug Fixes 🐛
|
|
76
|
+
- Perbaikan error atau issues di kode
|
|
77
|
+
- Improvement pada error handling
|
|
78
|
+
- Optimization performance
|
|
79
|
+
|
|
80
|
+
### Features ✨
|
|
81
|
+
- Fitur baru yang berguna
|
|
82
|
+
- Improvement pada dokumentasi
|
|
83
|
+
- Menambahkan tests
|
|
84
|
+
|
|
85
|
+
### Documentation 📚
|
|
86
|
+
- Improvement README
|
|
87
|
+
- Menambah contoh penggunaan
|
|
88
|
+
- Memperbaiki typos
|
|
89
|
+
|
|
90
|
+
## Area yang Bisa Dikontribusi
|
|
91
|
+
|
|
92
|
+
- [ ] Menambah fitur update (edit data existing)
|
|
93
|
+
- [ ] Implementasi async/await version
|
|
94
|
+
- [ ] Error handling yang lebih robust
|
|
95
|
+
- [ ] Unit tests menggunakan Jest
|
|
96
|
+
- [ ] Dokumentasi yang lebih lengkap
|
|
97
|
+
- [ ] Tutorial video/blog post
|
|
98
|
+
- [ ] Support untuk format file lain (CSV, XML)
|
|
99
|
+
- [ ] CLI interface untuk database
|
|
100
|
+
|
|
101
|
+
## Sebelum Submit PR
|
|
102
|
+
|
|
103
|
+
- ✅ Pastikan code tidak ada error
|
|
104
|
+
- ✅ Pastikan code sudah di-test
|
|
105
|
+
- ✅ Pastikan README/documentation updated (jika diperlukan)
|
|
106
|
+
- ✅ Pastikan commit message jelas dan deskriptif
|
|
107
|
+
- ✅ Pastikan tidak ada file yang tidak perlu di-commit
|
|
108
|
+
|
|
109
|
+
## Code of Conduct
|
|
110
|
+
|
|
111
|
+
Dalam berkontribusi pada project ini, kami mengharapkan semua kontributor untuk:
|
|
112
|
+
|
|
113
|
+
- 🤝 Saling menghormati dan membantu
|
|
114
|
+
- 💬 Berkomunikasi dengan jelas dan konstruktif
|
|
115
|
+
- 🎯 Fokus pada improvement quality code
|
|
116
|
+
- 📖 Membaca dan mengikuti guidelines yang ada
|
|
117
|
+
|
|
118
|
+
## Questions?
|
|
119
|
+
|
|
120
|
+
Jika Anda memiliki pertanyaan:
|
|
121
|
+
|
|
122
|
+
1. Buka [GitHub Issues](https://github.com/wa130/json-db-enginee/issues)
|
|
123
|
+
2. Atau hubungi saya di email: nasyuwa648@gmail.com
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
**Happy Contributing!** 🚀✨
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nasyuwa
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
# LearnJS - Database Management System
|
|
2
|
+
|
|
3
|
+
Selamat datang! Ini adalah project pembelajaran saya untuk memahami cara membuat sistem manajemen database sederhana menggunakan JavaScript dan Node.js.
|
|
4
|
+
|
|
5
|
+
## 📋 Deskripsi Project
|
|
6
|
+
|
|
7
|
+
Project ini merupakan implementasi **Database Class** dengan operasi **CRUD (Create, Read, Update, Delete)** yang dapat menyimpan dan mengelola data dalam file JSON. Melalui project ini, saya belajar tentang:
|
|
8
|
+
|
|
9
|
+
- Membuat class dan object-oriented programming di JavaScript
|
|
10
|
+
- Operasi file system (fs) di Node.js
|
|
11
|
+
- Manipulasi dan parsing data JSON
|
|
12
|
+
- Implementasi operasi CRUD
|
|
13
|
+
- ES Modules (import/export)
|
|
14
|
+
- Array methods: `.push()`, `.filter()`, `.find()`
|
|
15
|
+
- Pemisahan logic ke modul-modul terpisah
|
|
16
|
+
|
|
17
|
+
## 📁 Struktur Project
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
json-db-enginee/
|
|
21
|
+
├── module.js # Wrapper untuk module fs
|
|
22
|
+
├── load.js # Fungsi untuk load data dari file
|
|
23
|
+
├── read.js # Fungsi untuk membaca data terstruktur
|
|
24
|
+
├── add.js # Fungsi untuk menambah data
|
|
25
|
+
├── find.js # Fungsi untuk mencari data
|
|
26
|
+
├── delete.js # Fungsi untuk menghapus data
|
|
27
|
+
├── main.js # Class Database (inti aplikasi)
|
|
28
|
+
├── example.js # Demonstrasi lengkap semua operasi
|
|
29
|
+
├── example.json # File data (database)
|
|
30
|
+
├── package.json # Konfigurasi project
|
|
31
|
+
└── README.md # File dokumentasi ini
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## 🚀 Cara Memulai
|
|
35
|
+
|
|
36
|
+
### Prerequisites
|
|
37
|
+
- Node.js versi 12 atau lebih tinggi
|
|
38
|
+
- Text Editor/IDE (VS Code, dll)
|
|
39
|
+
|
|
40
|
+
### Install Dependencies
|
|
41
|
+
```bash
|
|
42
|
+
npm install
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Menjalankan Project
|
|
46
|
+
```bash
|
|
47
|
+
node example.js
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## 🏛️ Arsitektur Kode
|
|
51
|
+
|
|
52
|
+
### 1. **module.js** - Module Wrapper
|
|
53
|
+
Wrapper sederhana untuk module `fs` agar mudah di-import:
|
|
54
|
+
|
|
55
|
+
```javascript
|
|
56
|
+
import fs from 'fs'
|
|
57
|
+
|
|
58
|
+
export const mdl = {
|
|
59
|
+
fs: fs
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### 2. **load.js** - Load Data
|
|
64
|
+
Membaca file dan meng-parse data JSON ke array:
|
|
65
|
+
|
|
66
|
+
```javascript
|
|
67
|
+
export default function load(path) {
|
|
68
|
+
const dataPath = path
|
|
69
|
+
const data = mdl.fs.readFileSync(dataPath, 'utf-8')
|
|
70
|
+
return JSON.parse(data)
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### 3. **read.js** - Read Data
|
|
75
|
+
Membaca file dan langsung return data yang sudah di-parse:
|
|
76
|
+
|
|
77
|
+
```javascript
|
|
78
|
+
export default function read(path) {
|
|
79
|
+
const data = mdl.fs.readFileSync(dataPath, 'utf-8')
|
|
80
|
+
return JSON.parse(data)
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### 4. **add.js** - Create/Add Data
|
|
85
|
+
Menambahkan data baru ke array dan menyimpannya ke file:
|
|
86
|
+
|
|
87
|
+
```javascript
|
|
88
|
+
export default function add(path, data) {
|
|
89
|
+
const database = load(path)
|
|
90
|
+
database.push(data)
|
|
91
|
+
const dataPath = mdl.fs.writeFileSync(path, JSON.stringify(database, null, 2))
|
|
92
|
+
return dataPath
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### 5. **find.js** - Read/Search Data
|
|
97
|
+
Mencari data berdasarkan property dan value:
|
|
98
|
+
|
|
99
|
+
```javascript
|
|
100
|
+
export default function find(path, object, query) {
|
|
101
|
+
const database = load(path)
|
|
102
|
+
const cari = database.find((item) => item[object] === query)
|
|
103
|
+
return cari
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### 6. **delete.js** - Delete Data
|
|
108
|
+
Menghapus data berdasarkan property dan value:
|
|
109
|
+
|
|
110
|
+
```javascript
|
|
111
|
+
export default function deleted(path, object, query) {
|
|
112
|
+
const database = load(path)
|
|
113
|
+
const delet = database.filter((item) => item[object] !== query)
|
|
114
|
+
return mdl.fs.writeFileSync(path, JSON.stringify(delet, null, 2))
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### 7. **main.js** - Database Class
|
|
119
|
+
Class utama yang menggabungkan semua operasi:
|
|
120
|
+
|
|
121
|
+
```javascript
|
|
122
|
+
export default class Database {
|
|
123
|
+
constructor(path) {
|
|
124
|
+
this.path = path
|
|
125
|
+
load(this.path)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
read() {
|
|
129
|
+
return read(this.path)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
add(data) {
|
|
133
|
+
return add(this.path, data)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
find(object, query) {
|
|
137
|
+
return find(this.path, object, query)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
delete(object, query) {
|
|
141
|
+
return deleted(this.path, object, query)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## 💡 Contoh Penggunaan Lengkap
|
|
147
|
+
|
|
148
|
+
### 1. Inisialisasi Database
|
|
149
|
+
```javascript
|
|
150
|
+
import Database from './main.js'
|
|
151
|
+
|
|
152
|
+
const db = new Database('./example.json')
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### 2. Read - Membaca Semua Data
|
|
156
|
+
```javascript
|
|
157
|
+
const allData = db.read()
|
|
158
|
+
console.log(allData)
|
|
159
|
+
// Output: [{ name: 'johsh', age: 10 }, ...]
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### 3. Add - Menambah Data Baru
|
|
163
|
+
```javascript
|
|
164
|
+
const newUser = {
|
|
165
|
+
name: 'Nasyuwa',
|
|
166
|
+
age: 17
|
|
167
|
+
}
|
|
168
|
+
db.add(newUser)
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### 4. Find - Mencari Data
|
|
172
|
+
```javascript
|
|
173
|
+
const user = db.find('name', 'Budi Santoso')
|
|
174
|
+
console.log(user)
|
|
175
|
+
// Output: { name: 'Budi Santoso', age: 25 }
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### 5. Delete - Menghapus Data
|
|
179
|
+
```javascript
|
|
180
|
+
db.delete('name', 'johsh')
|
|
181
|
+
// Menghapus user dengan nama 'johsh' dari database
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## 📊 Format Data
|
|
185
|
+
|
|
186
|
+
Data disimpan dalam format JSON array:
|
|
187
|
+
|
|
188
|
+
```json
|
|
189
|
+
[
|
|
190
|
+
{
|
|
191
|
+
"name": "Nasyuwa",
|
|
192
|
+
"age": 17
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
]
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
## 🎯 Yang Saya Pelajari
|
|
199
|
+
|
|
200
|
+
### Konsep Pemrograman
|
|
201
|
+
✅ Object-Oriented Programming (Class)
|
|
202
|
+
✅ CRUD Operations (Create, Read, Update, Delete)
|
|
203
|
+
✅ Modular Code Organization
|
|
204
|
+
✅ ES Modules (import/export)
|
|
205
|
+
|
|
206
|
+
### JavaScript Features
|
|
207
|
+
✅ Array Methods: `.push()`, `.filter()`, `.find()`
|
|
208
|
+
✅ Arrow Functions: `(item) => item.name`
|
|
209
|
+
✅ Template Literals dan String Manipulation
|
|
210
|
+
✅ JSON Parsing dan Stringifying
|
|
211
|
+
|
|
212
|
+
### Node.js
|
|
213
|
+
✅ File System Module (`fs`)
|
|
214
|
+
✅ Synchronous File Operations
|
|
215
|
+
✅ Path Handling
|
|
216
|
+
✅ Module System
|
|
217
|
+
|
|
218
|
+
## 🔄 Alur Data
|
|
219
|
+
|
|
220
|
+
```
|
|
221
|
+
User Input
|
|
222
|
+
↓
|
|
223
|
+
Database Class (main.js)
|
|
224
|
+
↓
|
|
225
|
+
Fungsi Spesifik (add.js, find.js, delete.js, etc.)
|
|
226
|
+
↓
|
|
227
|
+
load.js (Parse JSON)
|
|
228
|
+
↓
|
|
229
|
+
File System (fs.readFileSync)
|
|
230
|
+
↓
|
|
231
|
+
example.json
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## ⚠️ Catatan & Pembaruan Ke Depan
|
|
235
|
+
|
|
236
|
+
### Catatan Saat Ini
|
|
237
|
+
- Menggunakan **synchronous file operations** untuk kesederhanaan pembelajaran
|
|
238
|
+
- Error handling masih minimal
|
|
239
|
+
|
|
240
|
+
### Improvement Ke Depan
|
|
241
|
+
- [ ] Menggunakan `async/await` untuk operasi file yang lebih efisien
|
|
242
|
+
- [ ] Menambahkan error handling yang lebih robust
|
|
243
|
+
- [ ] Validasi data sebelum menyimpan
|
|
244
|
+
- [ ] Menambahkan fitur update (edit data existing)
|
|
245
|
+
- [ ] Support untuk berbagai format file (CSV, XML, dll)
|
|
246
|
+
- [ ] Database validation schema
|
|
247
|
+
- [ ] Logging system
|
|
248
|
+
|
|
249
|
+
## 🛠️ Technologies Used
|
|
250
|
+
|
|
251
|
+
- **Language**: JavaScript (ES6+)
|
|
252
|
+
- **Runtime**: Node.js
|
|
253
|
+
- **Storage**: JSON Files
|
|
254
|
+
- **Module System**: ES Modules
|
|
255
|
+
|
|
256
|
+
## 📝 Cara Menjalankan Example
|
|
257
|
+
|
|
258
|
+
File `example.js` mendemonstrasikan semua operasi:
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
# Jalankan example
|
|
262
|
+
node example.js
|
|
263
|
+
|
|
264
|
+
# Output akan menampilkan:
|
|
265
|
+
# ✅ Database initialized
|
|
266
|
+
# 📖 READ - Membaca semua data
|
|
267
|
+
# ➕ ADD - Menambah data baru
|
|
268
|
+
# 🔍 FIND - Mencari data
|
|
269
|
+
# 🗑️ DELETE - Menghapus data
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
## 📚 Resources yang Membantu
|
|
273
|
+
|
|
274
|
+
- [MDN - Array Methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)
|
|
275
|
+
- [Node.js File System Documentation](https://nodejs.org/api/fs.html)
|
|
276
|
+
- [ES6 Modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules)
|
|
277
|
+
|
|
278
|
+
## 👨💻 Author
|
|
279
|
+
|
|
280
|
+
Dibuat sebagai bagian dari perjalanan pembelajaran JavaScript dan Node.js dari nol.
|
|
281
|
+
|
|
282
|
+
**Nama:** Nasyuwa
|
|
283
|
+
**Email:** nasyuwa648@gmail.com
|
|
284
|
+
**GitHub:** [@wa130](https://github.com/wa130)
|
|
285
|
+
|
|
286
|
+
## 📄 License
|
|
287
|
+
|
|
288
|
+
Project ini dilisensikan di bawah **MIT License** - lihat file [LICENSE](./LICENSE) untuk detail lengkapnya.
|
|
289
|
+
|
|
290
|
+
Anda bebas untuk:
|
|
291
|
+
- ✅ Menggunakan project ini untuk tujuan komersial maupun personal
|
|
292
|
+
- ✅ Memodifikasi dan mengubah kode sesuai kebutuhan
|
|
293
|
+
- ✅ Mendistribusikan ulang project ini
|
|
294
|
+
- ✅ Menggunakan project ini sebagai basis untuk project lain
|
|
295
|
+
|
|
296
|
+
Dengan syarat:
|
|
297
|
+
- 📋 Menyertakan lisensi dan copyright notice dalam setiap distribusi
|
|
298
|
+
|
|
299
|
+
---
|
|
300
|
+
|
|
301
|
+
**Happy Learning & Coding!** 🚀✨
|
|
302
|
+
|
|
303
|
+
*Jika Anda memiliki pertanyaan atau saran untuk improvement, feel free untuk membuat issues atau pull requests!*
|
package/add.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { mdl } from './module.js'
|
|
2
|
+
import load from './load.js'
|
|
3
|
+
|
|
4
|
+
export default function add(path, data) {
|
|
5
|
+
const database = load(path)
|
|
6
|
+
database.push(data)
|
|
7
|
+
const dataPath = mdl.fs.writeFileSync(path, JSON.stringify(database, null, 2))
|
|
8
|
+
return dataPath
|
|
9
|
+
}
|
|
10
|
+
|
package/delete.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { mdl } from './module.js'
|
|
2
|
+
import load from './load.js'
|
|
3
|
+
|
|
4
|
+
export default function deleted(path, object, query) {
|
|
5
|
+
const database = load(path)
|
|
6
|
+
const delet = database.filter((item) => item[object] !== query)
|
|
7
|
+
return mdl.fs.writeFileSync(path, JSON.stringify(delet, null, 2))
|
|
8
|
+
}
|
package/example.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import Database from './main.js'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
// ============================================
|
|
5
|
+
// INISIALISASI DATABASE
|
|
6
|
+
// ============================================
|
|
7
|
+
const db = new Database('./example.json')
|
|
8
|
+
console.log('✅ Database initialized at example.json\n')
|
|
9
|
+
|
|
10
|
+
// ============================================
|
|
11
|
+
// 1. READ - Membaca semua data
|
|
12
|
+
// ============================================
|
|
13
|
+
console.log('📖 READ - Membaca semua data:')
|
|
14
|
+
const allData = db.read()
|
|
15
|
+
console.log(JSON.stringify(allData, null, 2))
|
|
16
|
+
console.log('')
|
|
17
|
+
|
|
18
|
+
// ============================================
|
|
19
|
+
// 2. ADD - Menambah data baru
|
|
20
|
+
// ============================================
|
|
21
|
+
console.log('➕ ADD - Menambah data baru:')
|
|
22
|
+
const newUser = {
|
|
23
|
+
name: 'Nasyuwa',
|
|
24
|
+
age: 17
|
|
25
|
+
}
|
|
26
|
+
console.log('Data yang ditambahkan:', JSON.stringify(newUser, null, 2))
|
|
27
|
+
db.add(newUser)
|
|
28
|
+
console.log('✓ Data berhasil ditambahkan\n')
|
|
29
|
+
|
|
30
|
+
// Read lagi untuk melihat hasil penambahan
|
|
31
|
+
console.log('📖 Data setelah penambahan:')
|
|
32
|
+
const dataAfterAdd = db.read()
|
|
33
|
+
console.log(JSON.stringify(dataAfterAdd, null, 2))
|
|
34
|
+
console.log('')
|
|
35
|
+
|
|
36
|
+
// ============================================
|
|
37
|
+
// 3. FIND - Mencari data berdasarkan kriteria
|
|
38
|
+
// ============================================
|
|
39
|
+
console.log('🔍 FIND - Mencari data berdasarkan kriteria:')
|
|
40
|
+
console.log('Mencari user dengan nama = "johsh":')
|
|
41
|
+
const foundUser = db.find('name', 'johsh')
|
|
42
|
+
console.log(JSON.stringify(foundUser, null, 2))
|
|
43
|
+
console.log('')
|
|
44
|
+
|
|
45
|
+
console.log('Mencari user dengan nama = "Budi Santoso":')
|
|
46
|
+
const foundUser2 = db.find('name', 'Budi Santoso')
|
|
47
|
+
console.log(JSON.stringify(foundUser2, null, 2))
|
|
48
|
+
console.log('')
|
|
49
|
+
|
|
50
|
+
// ============================================
|
|
51
|
+
// 4. DELETE - Menghapus data berdasarkan kriteria
|
|
52
|
+
// ============================================
|
|
53
|
+
console.log('🗑️ DELETE - Menghapus data berdasarkan kriteria:')
|
|
54
|
+
console.log('Menghapus user dengan nama = "johsh":')
|
|
55
|
+
db.delete('name', 'johsh')
|
|
56
|
+
console.log('✓ Data berhasil dihapus\n')
|
|
57
|
+
|
|
58
|
+
// Read lagi untuk melihat hasil penghapusan
|
|
59
|
+
console.log('📖 Data setelah penghapusan:')
|
|
60
|
+
const dataAfterDelete = db.read()
|
|
61
|
+
console.log(JSON.stringify(dataAfterDelete, null, 2))
|
|
62
|
+
console.log('')
|
|
63
|
+
|
|
64
|
+
// ============================================
|
|
65
|
+
// KESIMPULAN
|
|
66
|
+
// ============================================
|
|
67
|
+
console.log('============================================')
|
|
68
|
+
console.log('✅ Semua operasi CRUD berhasil dijalankan!')
|
|
69
|
+
console.log('============================================')
|
|
70
|
+
console.log('\nRingkasan operasi:')
|
|
71
|
+
console.log('• READ - Membaca semua data dari file')
|
|
72
|
+
console.log('• ADD - Menambah data baru ke file')
|
|
73
|
+
console.log('• FIND - Mencari data berdasarkan property & value')
|
|
74
|
+
console.log('• DELETE - Menghapus data berdasarkan property & value')
|
|
75
|
+
|
|
76
|
+
|
package/find.js
ADDED
package/load.js
ADDED
package/main.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import load from './load.js'
|
|
2
|
+
import add from './add.js'
|
|
3
|
+
import find from './find.js'
|
|
4
|
+
import deleted from './delete.js'
|
|
5
|
+
import read from './read.js'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export default class Database {
|
|
9
|
+
constructor(path) {
|
|
10
|
+
this.path = path
|
|
11
|
+
load(this.path)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
read() {
|
|
15
|
+
return read(this.path)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
add(data) {
|
|
19
|
+
return add(this.path, data)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
find(object, query) {
|
|
23
|
+
return find(this.path, object, query)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
delete(object, query) {
|
|
27
|
+
return deleted(this.path, object, query)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
package/module.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "json-db-engine",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Database Management System sederhana menggunakan JSON dan Node.js File System",
|
|
5
|
+
"main": "main.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"start": "node example.js",
|
|
9
|
+
"dev": "node example.js",
|
|
10
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"database",
|
|
14
|
+
"json",
|
|
15
|
+
"crud",
|
|
16
|
+
"file-system",
|
|
17
|
+
"node.js",
|
|
18
|
+
"javascript",
|
|
19
|
+
"learning"
|
|
20
|
+
],
|
|
21
|
+
"author": {
|
|
22
|
+
"name": "Nasyuwa",
|
|
23
|
+
"email": "nasyuwa648@gmail.com",
|
|
24
|
+
"url": "https://github.com/wa130"
|
|
25
|
+
},
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "https://github.com/wa130/json-db-enginee.git"
|
|
29
|
+
},
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/wa130/json-db-enginee/issues"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://github.com/wa130/json-db-enginee#readme",
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=12.0.0"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {}
|
|
39
|
+
}
|