@goatlab/fluent 0.7.42 → 0.7.43
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/README.md +93 -52
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,61 +1,102 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
[![Stargazers][stars-shield]][stars-url]
|
|
4
|
-
[![Issues][issues-shield]][issues-url]
|
|
5
|
-
[![MIT License][license-shield]][license-url]
|
|
6
|
-
[](http://commitizen.github.io/cz-cli/)
|
|
7
|
-
|
|
8
|
-
<!-- PROJECT LOGO -->
|
|
9
|
-
<br />
|
|
10
|
-
<p align="center">
|
|
11
|
-
<a href="https://github.com/github_username/repo">
|
|
12
|
-
<img src="https://docs.goatlab.io/logo.png" alt="Logo" width="150" height="150">
|
|
13
|
-
</a>
|
|
14
|
-
|
|
15
|
-
<h3 align="center">GOAT - FLUENT</h3>
|
|
16
|
-
|
|
17
|
-
<p align="center">
|
|
18
|
-
Fluent - Time Saving (TS) utils
|
|
19
|
-
<br />
|
|
20
|
-
<a href="https://docs.goatlab.io/#/0.7.x/fluent/fluent"><strong>Explore the docs »</strong></a>
|
|
21
|
-
<br />
|
|
22
|
-
<br />
|
|
23
|
-
·
|
|
24
|
-
<a href="https://github.com/goat-io/fluent/issues">Report Bug</a>
|
|
25
|
-
·
|
|
26
|
-
<a href="https://github.com/goat-io/fluent/issues">Request Feature</a>
|
|
27
|
-
</p>
|
|
28
|
-
</p>
|
|
29
|
-
</p>
|
|
30
|
-
|
|
31
|
-
# Goat - Fluent
|
|
32
|
-
|
|
33
|
-
Fluent query interface for Multiple database types and helpers for fast API generation and general App building.
|
|
1
|
+
# @goatlab/fluent
|
|
34
2
|
|
|
35
|
-
|
|
3
|
+
A TypeScript query builder and ORM wrapper that provides a fluent interface for multiple database types with built-in validation using Zod schemas.
|
|
36
4
|
|
|
37
|
-
|
|
38
|
-
2. Mysql\*
|
|
39
|
-
3. MariaDB\*
|
|
40
|
-
4. SQLite\*
|
|
41
|
-
5. Postgres\*
|
|
42
|
-
6. CockroachDB\*
|
|
43
|
-
7. Microsoft SQL Server\*
|
|
44
|
-
8. Oracle\*
|
|
45
|
-
9. SAP Hana\*
|
|
46
|
-
10. sql.js\*
|
|
47
|
-
11. In-memory SQlite
|
|
5
|
+
## Installation
|
|
48
6
|
|
|
49
|
-
|
|
7
|
+
```bash
|
|
8
|
+
npm install @goatlab/fluent
|
|
9
|
+
# or
|
|
10
|
+
yarn add @goatlab/fluent
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @goatlab/fluent
|
|
13
|
+
```
|
|
50
14
|
|
|
51
|
-
|
|
15
|
+
## Basic Usage
|
|
52
16
|
|
|
53
|
-
|
|
17
|
+
```typescript
|
|
18
|
+
import { TypeOrmConnector, f } from '@goatlab/fluent'
|
|
19
|
+
import { DataSource } from 'typeorm'
|
|
20
|
+
import { z } from 'zod'
|
|
54
21
|
|
|
55
|
-
|
|
56
|
-
|
|
22
|
+
// Define your entity
|
|
23
|
+
@f.entity('users')
|
|
24
|
+
class User {
|
|
25
|
+
@f.id()
|
|
26
|
+
id: string
|
|
27
|
+
|
|
28
|
+
@f.property({ required: true, type: 'varchar' })
|
|
29
|
+
name: string
|
|
30
|
+
|
|
31
|
+
@f.property({ type: 'int' })
|
|
32
|
+
age?: number
|
|
33
|
+
|
|
34
|
+
@f.created()
|
|
35
|
+
created?: Date
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Define your schema
|
|
39
|
+
const UserSchema = z.object({
|
|
40
|
+
id: z.string().optional(),
|
|
41
|
+
name: z.string(),
|
|
42
|
+
age: z.number().optional(),
|
|
43
|
+
created: z.date().optional()
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
// Create a repository
|
|
47
|
+
class UserRepository extends TypeOrmConnector<User> {
|
|
48
|
+
constructor(dataSource: DataSource) {
|
|
49
|
+
super({
|
|
50
|
+
entity: User,
|
|
51
|
+
dataSource,
|
|
52
|
+
inputSchema: UserSchema
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Use the repository
|
|
58
|
+
const userRepo = new UserRepository(dataSource)
|
|
59
|
+
|
|
60
|
+
// Insert data
|
|
61
|
+
const user = await userRepo.insert({ name: 'John', age: 25 })
|
|
62
|
+
|
|
63
|
+
// Query data
|
|
64
|
+
const users = await userRepo.findMany({
|
|
65
|
+
where: { age: { $gte: 18 } },
|
|
66
|
+
orderBy: { name: 'asc' },
|
|
67
|
+
limit: 10
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
// Find by ID
|
|
71
|
+
const user = await userRepo.findById('user-id')
|
|
72
|
+
|
|
73
|
+
// Update
|
|
74
|
+
await userRepo.updateById('user-id', { name: 'Jane' })
|
|
75
|
+
|
|
76
|
+
// Delete
|
|
77
|
+
await userRepo.deleteById('user-id')
|
|
57
78
|
```
|
|
58
79
|
|
|
59
|
-
|
|
80
|
+
## Key Features
|
|
81
|
+
|
|
82
|
+
- **Multi-database support** - Works with MySQL, PostgreSQL, MongoDB, SQLite, and more via TypeORM
|
|
83
|
+
- **Fluent query interface** - Chainable query methods with TypeScript support
|
|
84
|
+
- **Built-in validation** - Automatic input/output validation using Zod schemas
|
|
85
|
+
- **Decorators** - Simple entity definition using decorators (`@f.entity`, `@f.property`, etc.)
|
|
86
|
+
- **Type safety** - Full TypeScript support with proper type inference
|
|
87
|
+
- **Relations** - Support for complex relationships between entities
|
|
88
|
+
- **Pagination** - Built-in pagination support
|
|
89
|
+
- **Raw queries** - Execute raw SQL when needed
|
|
90
|
+
|
|
91
|
+
## Supported Databases
|
|
60
92
|
|
|
61
|
-
|
|
93
|
+
All databases supported by TypeORM:
|
|
94
|
+
- MySQL / MariaDB
|
|
95
|
+
- PostgreSQL
|
|
96
|
+
- MongoDB
|
|
97
|
+
- SQLite
|
|
98
|
+
- Microsoft SQL Server
|
|
99
|
+
- Oracle
|
|
100
|
+
- CockroachDB
|
|
101
|
+
- SAP Hana
|
|
102
|
+
- And more...
|