Comparing version 0.1.0 to 0.1.1
@@ -338,6 +338,7 @@ import { | ||
}, lefts), | ||
() => recur([rights, me])); | ||
_ => recur([rights, me]), | ||
_ => me.hook && each(left => left._[me.as] = me.hook(left._[me.as]), lefts)); | ||
})); | ||
}, | ||
_ => lefts | ||
_ => me.hook ? me.hook(lefts) : lefts | ||
); | ||
@@ -433,2 +434,2 @@ } | ||
replace_q: _ => _ | ||
}); | ||
}); |
{ | ||
"name": "mql2", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "query builder", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -27,2 +27,4 @@ # MQL - Node.js 데이터베이스 쿼리 빌더 | ||
- [SET](#set) | ||
- [COLUMN, CL](#column-cl) | ||
- [TABLE, TB](#table-tb) | ||
- [Associations](#associations) | ||
@@ -33,2 +35,3 @@ - [기본](#기본) | ||
- [Many to many](#many-to-many) | ||
- [Hook](#hook) | ||
- [옵션](#옵션) | ||
@@ -54,4 +57,3 @@ - [DEBUG](#debug) | ||
password: '1234', | ||
database: 'dbname', | ||
charset: 'utf8' | ||
database: 'dbname' | ||
}); | ||
@@ -158,2 +160,32 @@ ``` | ||
### COLUMN, CL | ||
```javascript | ||
COLUMN == CL; // true | ||
await QUERY ` | ||
SELECT | ||
COLUMN('id', 'bb as cc', 't2.name', 't2.name as name2', { a: 'c' }, { 't3.a': 'd' }) | ||
... | ||
`; | ||
// SELECT | ||
// "id", "bb" AS "cc", "t2"."name", "t2"."name" AS "name2", "a" AS "c", "t3"."a" AS "d" | ||
// ... | ||
``` | ||
### TABLE, TB | ||
```javascript | ||
TABLE == TB; // true | ||
await QUERY ` | ||
SELECT | ||
... | ||
FROM TABLE('t1'), TABLE('tt as t2') | ||
`; | ||
// SELECT | ||
// ... | ||
// FROM "t1", "tt" AS "t2" | ||
``` | ||
## Associations | ||
@@ -169,2 +201,3 @@ | ||
* - id | ||
* - name | ||
* | ||
@@ -174,7 +207,9 @@ * posts | ||
* - user_id | ||
* - is_hidden | ||
* | ||
* - body | ||
* comments | ||
* - id | ||
* - user_id | ||
* - post_id | ||
* - is_hidden | ||
* - body | ||
* */ | ||
@@ -294,3 +329,3 @@ | ||
ASSOCIATE ` | ||
posts ${SQL `ORDER BY id DESC LIMIT ${10}`} | ||
posts ${SQL `WHERE is_hidden = false ORDER BY id DESC LIMIT ${10}`} | ||
- user | ||
@@ -368,2 +403,23 @@ < comments ${{ | ||
### Hook | ||
`hook`을 이용하여 가상 컬럼이나, 정렬, 필터 등의 추가 작업을 할 수 있습니다. 자신의 안쪽 데이터들이 모두 불려진 후 실행되어 활용하기 좋습니다. | ||
```javascript | ||
const users = await ASSOCIATE ` | ||
users ${{hook: users => users.map(u => | ||
Object.assign({}, u, { _popular: !!u._.posts.find(p => p._is_best) }) | ||
)}} | ||
< posts ${{hook: posts => posts.map( | ||
p => Object.assign({}, p, { _is_best: p._.comments.length > 1 }))}} | ||
- user | ||
< comments | ||
- user | ||
`; | ||
users[0]._popular; // true | ||
users[0]._.posts[0]._is_best; // true | ||
users[0]._.posts[1]._is_best; // false | ||
``` | ||
## Transaction | ||
@@ -370,0 +426,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26475
454