accel-record
Advanced tools
Comparing version 1.10.1 to 1.11.0
{ | ||
"name": "accel-record", | ||
"version": "1.10.1", | ||
"version": "1.11.0", | ||
"description": "Accel Record is a type-safe and synchronous ORM for TypeScript. It adopts the Active Record pattern and is heavily influenced by Ruby on Rails' Active Record.", | ||
@@ -45,6 +45,6 @@ "type": "module", | ||
"dependencies": { | ||
"accel-record-core": "^1.10.1", | ||
"accel-record-factory": "^1.10.1", | ||
"prisma-generator-accel-record": "^1.10.1" | ||
"accel-record-core": "^1.11.0", | ||
"accel-record-factory": "^1.11.0", | ||
"prisma-generator-accel-record": "^1.11.0" | ||
} | ||
} |
@@ -30,4 +30,5 @@ Language: [English](https://github.com/koyopro/accella/blob/main/packages/accel-record/README.md) | [日本語](https://github.com/koyopro/accella/blob/main/packages/accel-record/README-ja.md) | ||
- [Query Interface](#query-interface) | ||
- [Scopes](#scopes) | ||
- [Flexible Search](#flexible-search) | ||
- [Testing](#testing) | ||
- [Scopes](#scopes) | ||
- [Validation](#validation) | ||
@@ -783,2 +784,53 @@ - [Callbacks](#callbacks) | ||
## Flexible Search | ||
Using the `.search()` method, you can perform object-based flexible searches. | ||
(The interface is inspired by the Ransack gem.) | ||
Search parameters are specified as an object with keys representing the field name and search condition combination strings, and values representing the search values. | ||
You can include associations in the keys. | ||
The search conditions include `eq`, `cont`, `matches`, `lt`, `gte`, `in`, `null`, and more. | ||
In addition, modifiers such as `not`, `or`, `and`, `any`, `all` are also available. | ||
Please refer to the documentation of the search() method for more details. | ||
```ts | ||
import { User } from "./models/index.js"; | ||
const search = User.search({ | ||
name_eq: "John", // name equals "John" | ||
age_not_null: 1, // age is not null | ||
profile_bio_cont: "foo", // related profile's bio contains "foo" | ||
email_or_name_cont_any: ["bar", "baz"], // email or name contains "bar" or "baz" | ||
}); | ||
const users = search.result(); | ||
``` | ||
Additionally, you can include the names of searchable scopes defined in the `searchableScopes` array as keys in the search parameters. | ||
For example, the `bio_cont` scope defined as follows can be used in the search parameters: | ||
```ts | ||
// src/models/user.ts | ||
import { scope } from "accel-record"; | ||
import { ApplicationRecord } from "./applicationRecord.js"; | ||
class UserModel extends ApplicationRecord { | ||
@scope | ||
static bio_cont(value: string) { | ||
return this.joins("profile").where({ | ||
profile: { bio: { contains: value } }, | ||
}); | ||
} | ||
static searchableScopes = ["bio_cont"]; | ||
} | ||
``` | ||
```ts | ||
import { User } from "./models/index.js"; | ||
const search = User.search({ bio_cont: "foo" }); // profile's bio contains "foo" | ||
const users = search.result(); | ||
``` | ||
## Testing | ||
@@ -1294,4 +1346,3 @@ | ||
- [accel-record-core] Support for Composite IDs | ||
- [accel-record-core] Expansion of Query Interface | ||
Related: [Accel Record Roadmap](https://github.com/koyopro/accella/issues/1) |
37232
1346