ruggy 0.1.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 +65 -0
- package/LICENSE +21 -0
- package/README.md +315 -0
- package/assets/icon.jpeg +0 -0
- package/index.d.ts +288 -0
- package/lib/ruggy.dll +0 -0
- package/package.json +42 -0
- package/src/Collection.js +176 -0
- package/src/Database.js +217 -0
- package/src/Pool.js +251 -0
- package/src/bindings.js +34 -0
- package/src/config.js +124 -0
- package/src/index.js +58 -0
- package/src/utils.js +73 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.1.0] - 2026-01-04
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Initial release of Ruggy embedded database
|
|
12
|
+
- Basic CRUD operations (insert, findAll, find)
|
|
13
|
+
- Connection pooling with `RuggyPool`
|
|
14
|
+
- YAML configuration support via `ruggy.yaml`
|
|
15
|
+
- Configuration loader with automatic file discovery
|
|
16
|
+
- `Database.fromConfig()` and `Pool.fromConfig()` factory methods
|
|
17
|
+
- Full TypeScript type definitions
|
|
18
|
+
- Comprehensive README with examples
|
|
19
|
+
- Support for Node.js 14+
|
|
20
|
+
- Windows x64 pre-built binaries
|
|
21
|
+
|
|
22
|
+
### Features
|
|
23
|
+
- Native Rust backend with FFI bindings
|
|
24
|
+
- Embedded database (no external server required)
|
|
25
|
+
- Simple and intuitive API
|
|
26
|
+
- Persistent storage with append-only files
|
|
27
|
+
- Flexible YAML configuration
|
|
28
|
+
- TypeScript support with complete definitions
|
|
29
|
+
|
|
30
|
+
### Platform Support
|
|
31
|
+
- Windows x64 - Pre-built binaries included
|
|
32
|
+
- Linux - Not supported at this time
|
|
33
|
+
- macOS - Not supported at this time
|
|
34
|
+
|
|
35
|
+
### Known Limitations
|
|
36
|
+
- Single-platform binary distribution (Windows only)
|
|
37
|
+
- No query operators (only exact match)
|
|
38
|
+
- No indexes (linear scan)
|
|
39
|
+
- No transactions
|
|
40
|
+
- No schema validation
|
|
41
|
+
|
|
42
|
+
### Dependencies
|
|
43
|
+
- koffi ^2.8.0 - FFI bindings
|
|
44
|
+
- js-yaml ^4.1.0 - YAML configuration parsing
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## [Unreleased]
|
|
49
|
+
|
|
50
|
+
### Planned for 0.2.0
|
|
51
|
+
- Linux and macOS pre-built binaries
|
|
52
|
+
- Configurable limits (maxCollectionSize, maxDocumentSize)
|
|
53
|
+
- Logging configuration
|
|
54
|
+
- Performance tuning options
|
|
55
|
+
|
|
56
|
+
### Future Enhancements
|
|
57
|
+
- Backup automation
|
|
58
|
+
- Compression support
|
|
59
|
+
- Query operators (range, comparison)
|
|
60
|
+
- Basic indexing
|
|
61
|
+
- Encryption at rest
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
[0.1.0]: https://github.com/Mub1522/ruggy/releases/tag/v0.1.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Andres Diaz
|
|
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,315 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/Mub1522/ruggy/main/assets/icon.jpeg" alt="Ruggy Logo" width="200"/>
|
|
3
|
+
</div>
|
|
4
|
+
|
|
5
|
+
<h1 style="text-align: center;">Ruggy</h1>
|
|
6
|
+
|
|
7
|
+
<p style="text-align: center;">A simple, fast embedded database for Node.js backed by Rust.</p>
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Fast** - Native Rust backend with FFI bindings
|
|
12
|
+
- **Embedded** - No separate database server required
|
|
13
|
+
- **Simple** - Clean, intuitive API
|
|
14
|
+
- **Persistent** - Data stored in append-only files
|
|
15
|
+
- **Type-Safe** - Full TypeScript support
|
|
16
|
+
- **Configurable** - YAML configuration for flexible deployment
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install ruggy
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
```javascript
|
|
27
|
+
const { RuggyDatabase } = require('ruggy');
|
|
28
|
+
|
|
29
|
+
// Create/open database
|
|
30
|
+
const db = new RuggyDatabase('./data');
|
|
31
|
+
|
|
32
|
+
// Get a collection
|
|
33
|
+
const users = db.collection('users');
|
|
34
|
+
|
|
35
|
+
// Insert documents
|
|
36
|
+
const id = users.insert({ name: 'Alice', email: 'alice@example.com' });
|
|
37
|
+
|
|
38
|
+
// Find all documents
|
|
39
|
+
const allUsers = users.findAll();
|
|
40
|
+
|
|
41
|
+
// Find by field
|
|
42
|
+
const results = users.find('email', 'alice@example.com');
|
|
43
|
+
|
|
44
|
+
// Close when done
|
|
45
|
+
db.close();
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Platform Support
|
|
49
|
+
|
|
50
|
+
| Platform | Status | Pre-built Binaries |
|
|
51
|
+
|----------|--------|-------------------|
|
|
52
|
+
| **Windows x64** | ✅ Fully Supported | ✅ Included |
|
|
53
|
+
| **Linux x64** | Not supported | Not included |
|
|
54
|
+
| **macOS (Intel)** | Not supported | Not included |
|
|
55
|
+
| **macOS (ARM)** | Not supported | Not included |
|
|
56
|
+
|
|
57
|
+
> **Note:** Version 0.1.0 includes pre-built binaries for Windows only. Linux and macOS users will need Rust installed to build from source. Multi-platform binaries are planned for v0.2.0.
|
|
58
|
+
|
|
59
|
+
## Configuration
|
|
60
|
+
|
|
61
|
+
Create a `ruggy.yaml` file in your project root to configure the database path:
|
|
62
|
+
|
|
63
|
+
```yaml
|
|
64
|
+
dataPath: ./my-database
|
|
65
|
+
# or use absolute path
|
|
66
|
+
# dataPath: /var/data/ruggy
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Then use the configuration-based factory:
|
|
70
|
+
|
|
71
|
+
```javascript
|
|
72
|
+
const { RuggyDatabase } = require('ruggy');
|
|
73
|
+
|
|
74
|
+
// Automatically uses path from ruggy.yaml
|
|
75
|
+
const db = RuggyDatabase.fromConfig();
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
If no `ruggy.yaml` is found, Ruggy defaults to `./data`.
|
|
79
|
+
|
|
80
|
+
## API Reference
|
|
81
|
+
|
|
82
|
+
### RuggyDatabase
|
|
83
|
+
|
|
84
|
+
#### Constructor
|
|
85
|
+
|
|
86
|
+
```javascript
|
|
87
|
+
new RuggyDatabase(path: string)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Creates a new database at the specified path.
|
|
91
|
+
|
|
92
|
+
#### Static Methods
|
|
93
|
+
|
|
94
|
+
**`RuggyDatabase.fromConfig(options?)`**
|
|
95
|
+
|
|
96
|
+
Creates a database instance using `ruggy.yaml` configuration.
|
|
97
|
+
|
|
98
|
+
- **options.reload** `boolean` - Force reload configuration (bypass cache)
|
|
99
|
+
- **options.searchFrom** `string` - Directory to start searching for `ruggy.yaml`
|
|
100
|
+
|
|
101
|
+
**`RuggyDatabase.withDatabase(path, callback)`**
|
|
102
|
+
|
|
103
|
+
Automatically manages database lifecycle.
|
|
104
|
+
|
|
105
|
+
```javascript
|
|
106
|
+
await RuggyDatabase.withDatabase('./data', async (db) => {
|
|
107
|
+
const users = db.collection('users');
|
|
108
|
+
users.insert({ name: 'Bob' });
|
|
109
|
+
// Database automatically closed after callback
|
|
110
|
+
});
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
#### Instance Methods
|
|
114
|
+
|
|
115
|
+
**`collection(name: string): RuggyCollection`**
|
|
116
|
+
|
|
117
|
+
Gets or creates a collection.
|
|
118
|
+
|
|
119
|
+
**`withCollection(name, callback): Promise<any>`**
|
|
120
|
+
|
|
121
|
+
Executes callback with a collection, automatically closing it after.
|
|
122
|
+
|
|
123
|
+
```javascript
|
|
124
|
+
await db.withCollection('users', async (users) => {
|
|
125
|
+
const id = users.insert({ name: 'Charlie' });
|
|
126
|
+
return id;
|
|
127
|
+
});
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
**`close(): void`**
|
|
131
|
+
|
|
132
|
+
Closes the database and releases resources.
|
|
133
|
+
|
|
134
|
+
**Properties:**
|
|
135
|
+
- `path: string` - Database path
|
|
136
|
+
- `isOpen: boolean` - Whether database is open
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
### RuggyCollection
|
|
141
|
+
|
|
142
|
+
#### Instance Methods
|
|
143
|
+
|
|
144
|
+
**`insert(data: Object): string | null`**
|
|
145
|
+
|
|
146
|
+
Inserts a document and returns generated ID.
|
|
147
|
+
|
|
148
|
+
```javascript
|
|
149
|
+
const id = collection.insert({ name: 'Alice', age: 30 });
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
**`findAll(): Array<Object>`**
|
|
153
|
+
|
|
154
|
+
Returns all documents in the collection.
|
|
155
|
+
|
|
156
|
+
**`find(field: string, value: any): Array<Object>`**
|
|
157
|
+
|
|
158
|
+
Finds documents where field matches value.
|
|
159
|
+
|
|
160
|
+
```javascript
|
|
161
|
+
const adults = collection.find('age', '30');
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
**`close(): void`**
|
|
165
|
+
|
|
166
|
+
Closes the collection and releases resources.
|
|
167
|
+
|
|
168
|
+
**Properties:**
|
|
169
|
+
- `name: string` - Collection name
|
|
170
|
+
- `isOpen: boolean` - Whether collection is open
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
### RuggyPool
|
|
175
|
+
|
|
176
|
+
Connection pool for long-running applications.
|
|
177
|
+
|
|
178
|
+
#### Constructor
|
|
179
|
+
|
|
180
|
+
```javascript
|
|
181
|
+
new RuggyPool(path: string, options?)
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
**Options:**
|
|
185
|
+
- `lazyConnect: boolean` - Don't open DB until first use (default: `true`)
|
|
186
|
+
|
|
187
|
+
#### Static Methods
|
|
188
|
+
|
|
189
|
+
**`RuggyPool.fromConfig(options?)`**
|
|
190
|
+
|
|
191
|
+
Creates a pool instance using `ruggy.yaml` configuration.
|
|
192
|
+
|
|
193
|
+
```javascript
|
|
194
|
+
const pool = RuggyPool.fromConfig();
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
#### Instance Methods
|
|
198
|
+
|
|
199
|
+
**`withDatabase(callback): Promise<any>`**
|
|
200
|
+
|
|
201
|
+
Executes callback with the pooled database connection.
|
|
202
|
+
|
|
203
|
+
**`withCollection(name, callback): Promise<any>`**
|
|
204
|
+
|
|
205
|
+
Executes callback with a collection from the pool.
|
|
206
|
+
|
|
207
|
+
```javascript
|
|
208
|
+
const pool = new RuggyPool('./data');
|
|
209
|
+
|
|
210
|
+
await pool.withCollection('users', async (users) => {
|
|
211
|
+
users.insert({ name: 'Dave' });
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
await pool.closeGracefully();
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
**`close(): void`**
|
|
218
|
+
|
|
219
|
+
Immediately closes the pool.
|
|
220
|
+
|
|
221
|
+
**`closeGracefully(timeoutMs?): Promise<void>`**
|
|
222
|
+
|
|
223
|
+
Waits for active operations to complete before closing.
|
|
224
|
+
|
|
225
|
+
**`getStats(): Object`**
|
|
226
|
+
|
|
227
|
+
Returns pool statistics (connected, activeOperations, totalOperations).
|
|
228
|
+
|
|
229
|
+
**Properties:**
|
|
230
|
+
- `path: string` - Database path
|
|
231
|
+
- `isConnected: boolean` - Whether pool has active connection
|
|
232
|
+
- `isClosed: boolean` - Whether pool is closed
|
|
233
|
+
- `activeOperations: number` - Current active operations
|
|
234
|
+
- `totalOperations: number` - Total operations performed
|
|
235
|
+
|
|
236
|
+
## Examples
|
|
237
|
+
|
|
238
|
+
### Basic CRUD Operations
|
|
239
|
+
|
|
240
|
+
```javascript
|
|
241
|
+
const { RuggyDatabase } = require('ruggy');
|
|
242
|
+
const db = new RuggyDatabase('./data');
|
|
243
|
+
|
|
244
|
+
const products = db.collection('products');
|
|
245
|
+
|
|
246
|
+
// Create
|
|
247
|
+
const id = products.insert({
|
|
248
|
+
name: 'Laptop',
|
|
249
|
+
price: 999,
|
|
250
|
+
category: 'electronics'
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
// Read
|
|
254
|
+
const all = products.findAll();
|
|
255
|
+
const electronics = products.find('category', 'electronics');
|
|
256
|
+
|
|
257
|
+
// Close
|
|
258
|
+
db.close();
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### Using Connection Pool
|
|
262
|
+
|
|
263
|
+
```javascript
|
|
264
|
+
const { RuggyPool } = require('ruggy');
|
|
265
|
+
const pool = RuggyPool.fromConfig(); // Uses ruggy.yaml
|
|
266
|
+
|
|
267
|
+
// Multiple concurrent operations
|
|
268
|
+
await Promise.all([
|
|
269
|
+
pool.withCollection('users', async (col) => {
|
|
270
|
+
col.insert({ name: 'User 1' });
|
|
271
|
+
}),
|
|
272
|
+
pool.withCollection('logs', async (col) => {
|
|
273
|
+
col.insert({ event: 'startup' });
|
|
274
|
+
})
|
|
275
|
+
]);
|
|
276
|
+
|
|
277
|
+
await pool.closeGracefully();
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
### Using Modern Syntax (Node.js 20+)
|
|
281
|
+
|
|
282
|
+
```javascript
|
|
283
|
+
{
|
|
284
|
+
using db = new RuggyDatabase('./data');
|
|
285
|
+
const users = db.collection('users');
|
|
286
|
+
users.insert({ name: 'Eve' });
|
|
287
|
+
// Automatically closed when leaving scope
|
|
288
|
+
}
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
## Performance
|
|
294
|
+
|
|
295
|
+
Ruggy is optimized for embedded use cases with thousands of documents. For large-scale applications, consider a full database server.
|
|
296
|
+
|
|
297
|
+
**Benchmarks** (approximate):
|
|
298
|
+
- Insert: ~10,000 ops/sec
|
|
299
|
+
- FindAll: ~50,000 ops/sec
|
|
300
|
+
- Find by field: ~20,000 ops/sec
|
|
301
|
+
|
|
302
|
+
## License
|
|
303
|
+
|
|
304
|
+
MIT
|
|
305
|
+
|
|
306
|
+
## Contributing
|
|
307
|
+
|
|
308
|
+
Contributions welcome! Please open an issue or submit a pull request.
|
|
309
|
+
|
|
310
|
+
## Acknowledgments
|
|
311
|
+
|
|
312
|
+
Built with:
|
|
313
|
+
- [Koffi](https://github.com/Koromix/koffi) - FFI bindings
|
|
314
|
+
- [js-yaml](https://github.com/nodeca/js-yaml) - YAML parsing
|
|
315
|
+
- [Rust](https://www.rust-lang.org/) - Native backend
|
package/assets/icon.jpeg
ADDED
|
Binary file
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
// Type definitions for Ruggy
|
|
2
|
+
// Project: Ruggy
|
|
3
|
+
// Definitions by: Andres Diaz
|
|
4
|
+
|
|
5
|
+
/// <reference types="node" />
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Configuration options for loading ruggy.yaml
|
|
9
|
+
*/
|
|
10
|
+
export interface ConfigOptions {
|
|
11
|
+
/** Force reload configuration (bypass cache) */
|
|
12
|
+
reload?: boolean;
|
|
13
|
+
/** Directory to start searching for ruggy.yaml */
|
|
14
|
+
searchFrom?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Pool creation options
|
|
19
|
+
*/
|
|
20
|
+
export interface PoolOptions {
|
|
21
|
+
/** If true, don't open DB until first use (default: true) */
|
|
22
|
+
lazyConnect?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Combined configuration and pool options
|
|
27
|
+
*/
|
|
28
|
+
export interface PoolConfigOptions extends ConfigOptions, PoolOptions { }
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Pool statistics
|
|
32
|
+
*/
|
|
33
|
+
export interface PoolStats {
|
|
34
|
+
/** Database path */
|
|
35
|
+
path: string;
|
|
36
|
+
/** Whether pool has active connection */
|
|
37
|
+
connected: boolean;
|
|
38
|
+
/** Whether pool is closed */
|
|
39
|
+
closed: boolean;
|
|
40
|
+
/** Current active operations */
|
|
41
|
+
activeOperations: number;
|
|
42
|
+
/** Total operations performed */
|
|
43
|
+
totalOperations: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Ruggy Collection - Represents a collection in the database
|
|
48
|
+
*/
|
|
49
|
+
export class RuggyCollection {
|
|
50
|
+
/**
|
|
51
|
+
* Collection name
|
|
52
|
+
*/
|
|
53
|
+
readonly name: string;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Whether the collection is open
|
|
57
|
+
*/
|
|
58
|
+
readonly isOpen: boolean;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Inserts a document into the collection
|
|
62
|
+
* @param data - Document to insert
|
|
63
|
+
* @returns Generated document ID or null on error
|
|
64
|
+
*/
|
|
65
|
+
insert(data: Record<string, any>): string | null;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Finds all documents in the collection
|
|
69
|
+
* @returns Array of documents
|
|
70
|
+
*/
|
|
71
|
+
findAll(): Array<Record<string, any>>;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Finds documents matching a field-value pair
|
|
75
|
+
* @param field - Field name to search
|
|
76
|
+
* @param value - Value to match
|
|
77
|
+
* @returns Array of matching documents
|
|
78
|
+
*/
|
|
79
|
+
find(field: string, value: any): Array<Record<string, any>>;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Closes the collection and frees native resources
|
|
83
|
+
*/
|
|
84
|
+
close(): void;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Symbol.dispose implementation for "using" syntax (Node.js 20+)
|
|
88
|
+
*/
|
|
89
|
+
[Symbol.dispose](): void;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Symbol.asyncDispose implementation for "await using" syntax
|
|
93
|
+
*/
|
|
94
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Ruggy Database - A simple, fast embedded database
|
|
99
|
+
*/
|
|
100
|
+
export class RuggyDatabase {
|
|
101
|
+
/**
|
|
102
|
+
* Creates a new database connection
|
|
103
|
+
* @param dbPath - Path to the database directory
|
|
104
|
+
*/
|
|
105
|
+
constructor(dbPath: string);
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Database path
|
|
109
|
+
*/
|
|
110
|
+
readonly path: string;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Whether the database is open
|
|
114
|
+
*/
|
|
115
|
+
readonly isOpen: boolean;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Gets a collection (creates if doesn't exist)
|
|
119
|
+
* @param name - Collection name
|
|
120
|
+
* @returns Collection instance
|
|
121
|
+
*/
|
|
122
|
+
collection(name: string): RuggyCollection;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Alias for collection() for semantic clarity
|
|
126
|
+
* @param name - Collection name
|
|
127
|
+
* @returns Collection instance
|
|
128
|
+
*/
|
|
129
|
+
createCollection(name: string): RuggyCollection;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Helper: Automatically manages collection lifecycle
|
|
133
|
+
* @param name - Collection name
|
|
134
|
+
* @param callback - Async function that receives the collection
|
|
135
|
+
* @returns Result of callback
|
|
136
|
+
*/
|
|
137
|
+
withCollection<T>(name: string, callback: (collection: RuggyCollection) => Promise<T>): Promise<T>;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Closes the database and frees native resources
|
|
141
|
+
*/
|
|
142
|
+
close(): void;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Static helper: Automatically manages database lifecycle
|
|
146
|
+
* @param path - Database path
|
|
147
|
+
* @param callback - Async function that receives the database
|
|
148
|
+
* @returns Result of callback
|
|
149
|
+
*/
|
|
150
|
+
static withDatabase<T>(path: string, callback: (db: RuggyDatabase) => Promise<T>): Promise<T>;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Static factory: Creates a database instance using ruggy.yaml configuration
|
|
154
|
+
* @param options - Configuration options
|
|
155
|
+
* @returns Database instance configured from YAML
|
|
156
|
+
*/
|
|
157
|
+
static fromConfig(options?: ConfigOptions): RuggyDatabase;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Symbol.dispose implementation for "using" syntax (Node.js 20+)
|
|
161
|
+
*/
|
|
162
|
+
[Symbol.dispose](): void;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Symbol.asyncDispose implementation for "await using" syntax
|
|
166
|
+
*/
|
|
167
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Ruggy Pool - Connection pool for long-running applications
|
|
172
|
+
*/
|
|
173
|
+
export class RuggyPool {
|
|
174
|
+
/**
|
|
175
|
+
* Creates a new connection pool
|
|
176
|
+
* @param path - Database path
|
|
177
|
+
* @param options - Pool options
|
|
178
|
+
*/
|
|
179
|
+
constructor(path: string, options?: PoolOptions);
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Database path
|
|
183
|
+
*/
|
|
184
|
+
readonly path: string;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Whether the pool is closed
|
|
188
|
+
*/
|
|
189
|
+
readonly isClosed: boolean;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Whether there's an active connection
|
|
193
|
+
*/
|
|
194
|
+
readonly isConnected: boolean;
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Number of active operations
|
|
198
|
+
*/
|
|
199
|
+
readonly activeOperations: number;
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Total number of operations performed
|
|
203
|
+
*/
|
|
204
|
+
readonly totalOperations: number;
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Gets pool statistics
|
|
208
|
+
* @returns Pool statistics object
|
|
209
|
+
*/
|
|
210
|
+
getStats(): PoolStats;
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Executes a callback with a database connection
|
|
214
|
+
* @param callback - Async function that receives the database
|
|
215
|
+
* @returns Result of callback
|
|
216
|
+
*/
|
|
217
|
+
withDatabase<T>(callback: (db: RuggyDatabase) => Promise<T>): Promise<T>;
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Alias for withDatabase
|
|
221
|
+
* @param callback - Async function that receives the database
|
|
222
|
+
* @returns Result of callback
|
|
223
|
+
*/
|
|
224
|
+
withDB<T>(callback: (db: RuggyDatabase) => Promise<T>): Promise<T>;
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Helper: Executes a callback with a collection from the pooled database
|
|
228
|
+
* @param collectionName - Collection name
|
|
229
|
+
* @param callback - Async function that receives the collection
|
|
230
|
+
* @returns Result of callback
|
|
231
|
+
*/
|
|
232
|
+
withCollection<T>(collectionName: string, callback: (collection: RuggyCollection) => Promise<T>): Promise<T>;
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Closes the pooled connection and releases resources
|
|
236
|
+
*/
|
|
237
|
+
close(): void;
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Waits for all active operations to complete, then closes the pool
|
|
241
|
+
* @param timeoutMs - Maximum time to wait in milliseconds (default: 5000)
|
|
242
|
+
*/
|
|
243
|
+
closeGracefully(timeoutMs?: number): Promise<void>;
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Static factory: Creates a pool instance using ruggy.yaml configuration
|
|
247
|
+
* @param options - Combined configuration and pool options
|
|
248
|
+
* @returns Pool instance configured from YAML
|
|
249
|
+
*/
|
|
250
|
+
static fromConfig(options?: PoolConfigOptions): RuggyPool;
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Symbol.dispose implementation for "using" syntax (Node.js 20+)
|
|
254
|
+
*/
|
|
255
|
+
[Symbol.dispose](): void;
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Symbol.asyncDispose implementation for "await using" syntax
|
|
259
|
+
*/
|
|
260
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Configuration loader
|
|
265
|
+
*/
|
|
266
|
+
export interface Config {
|
|
267
|
+
/** Database data path */
|
|
268
|
+
dataPath: string;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Loads Ruggy configuration from ruggy.yaml or returns defaults
|
|
273
|
+
* @param options - Configuration options
|
|
274
|
+
* @returns Configuration object
|
|
275
|
+
*/
|
|
276
|
+
export function loadConfig(options?: ConfigOptions): Config;
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Clears the cached configuration
|
|
280
|
+
*/
|
|
281
|
+
export function clearCache(): void;
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Default configuration values
|
|
285
|
+
*/
|
|
286
|
+
export const DEFAULT_CONFIG: Config;
|
|
287
|
+
|
|
288
|
+
export { RuggyDatabase, RuggyCollection, RuggyPool };
|
package/lib/ruggy.dll
ADDED
|
Binary file
|