Socket
Socket
Sign inDemoInstall

mql2

Package Overview
Dependencies
53
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.4 to 0.1.5

16

mql.js

@@ -28,2 +28,3 @@ import {

const cmap = curry((f, arr) => Promise.all(arr.map(f)));
const first = a => a && a[0];

@@ -371,2 +372,6 @@ const is_column = f => f && f[SymbolColumn];

const QUERY1 = pipe(QUERY, first),
ASSOCIATE = baseAssociate(QUERY),
ASSOCIATE1 = pipe(ASSOCIATE, first);
const ljoin = use_ljoin ? await load_ljoin({

@@ -380,3 +385,5 @@ ready_sqls, add_column, tag, MQL_DEBUG,

QUERY,
ASSOCIATE: baseAssociate(QUERY),
QUERY1,
ASSOCIATE,
ASSOCIATE1,
LJOIN: ljoin(QUERY),

@@ -391,6 +398,11 @@ async TRANSACTION() {

}
const QUERY1 = pipe(QUERY, first),
ASSOCIATE = baseAssociate(QUERY),
ASSOCIATE1 = pipe(ASSOCIATE, first);
return {
VALUES, IN, NOT_IN, EQ, SET, COLUMN, CL, TABLE, TB, SQL,
QUERY,
ASSOCIATE: baseAssociate(QUERY),
QUERY1,
ASSOCIATE,
ASSOCIATE1,
LJOIN: ljoin(QUERY),

@@ -397,0 +409,0 @@ COMMIT: _ => COMMIT(client),

{
"name": "mql2",
"version": "0.1.4",
"version": "0.1.5",
"description": "query builder",

@@ -13,2 +13,12 @@ "main": "index.js",

},
"keywords": [
"functional",
"orm",
"sql query builder",
"template literals",
"tagged template literals",
"sql injection",
"mysql",
"postgresql"
],
"files": [

@@ -15,0 +25,0 @@ "mql.js",

142

README.md

@@ -1,24 +0,28 @@

# MQL - Node.js 데이터베이스 쿼리 빌더
# MQL - Node.js Functional SQL Query Builder & ORM
## 특징
- INSERT, UPDATE, WHERE 절 등에 필요한 복잡한 쿼리를 자바스크립트 객체를 통해 쉽게 생성할 수 있습니다.
- 일반적인 SQL 문법을 유지할 수 있어, 서브 쿼리, 조인 등을 쉽게 작성할 수 있습니다.
- SQL을 세밀하게 튜닝하고 발전시키기 쉽습니다.
- 각 데이터베이스에서 지원하는 다양한 최신 Operator 들을 쉽게 사용할 수 있습니다.
- (예. https://www.postgresql.org/docs/current/static/functions-json.html)
- SQL Injection 공격이 불가능합니다.
- Associations을 위해 모델을 미리 구성해둘 필요가 없습니다.
- Transaction을 사용하기 쉽습니다.
- 인자와 결과 값을 자바스크립트의 기본 값으로만(object, array, string, number, true, false, null) 구성하여, 조합성이 높고 JSON 변환 비용이 없습니다.
- PostgreSQL, MySQL 지원
[EN](https://github.com/marpple/MQL) | [KR](https://github.com/marpple/MQL/blob/master/README_kr.md)
## 목차
- [설치](#설치)
- [연결](#연결)
## Features
- Tagged template literal
- No models.
- Only need functions and javascript data types.
- Promises
- No cost for converting to JSON.
- More freedom in using SQL syntax.
- Preventing SQL-injection attacks.
- Easy to use the latest operators provided in databases.
- Simple transaction API.
- No models for Associations.
- Designed to work well with PostgreSQL, MySQL.
## Overview
- [Installation](#Installation)
- [Connect](#Connect)
- [PostgreSQL](#postgresql)
- [MySQL](#mysql)
- [간단한 쿼리](#간단한-쿼리)
- [서브 쿼리, 조인](#서브-쿼리-조인)
- [함수 불러오기](#함수-불러오기)
- [지원하는 헬퍼 함수](#지원하는-헬퍼-함수)
- [Simple query](#Simple-query)
- [Subquery, Join](#Subquery-Join)
- [Ready to be used](#Ready-to-be-used)
- [Helper Function](#Helper-Function)
- [EQ](#eq)

@@ -32,3 +36,3 @@ - [IN](#in)

- [Associations](#associations)
- [기본](#기본)
- [Common use](#Common-use)
- [Polymorphic](#polymorphic)

@@ -38,6 +42,6 @@ - [Transaction](#transaction)

- [Hook](#hook)
- [옵션](#옵션)
- [Option](#Option)
- [DEBUG](#debug)
## 설치
## Installation

@@ -48,3 +52,3 @@ ```

## 연결
## Connect

@@ -64,5 +68,5 @@ ### PostgreSQL

### PostgreSQL Connection 옵션
### PostgreSQL Connection option
MQL은 내부적으로 node-postgres를 사용합니다. `CONNECT` 함수에 사용되는 옵션은 node-postgres와 동일합니다. [디비 연결](https://node-postgres.com/features/connecting)이나 [커넥션 풀](https://node-postgres.com/api/pool)과 관련된 자세한 옵션은 [node-postgres](https://node-postgres.com/) 사이트에서 확인할 수 있습니다.
MQL is built on node-postgres. The parameter of CONNECT function is the same as node-postgres’. You can read the detail of [connection pool](https://node-postgres.com/api/pool) or [connecting to DB](https://node-postgres.com/features/connecting) on [node-postgres’ site](https://node-postgres.com/).

@@ -82,7 +86,7 @@ ### MySQL

### MySQL Connection 옵션
### MySQL Connection option
MQL은 내부적으로 mysql를 사용합니다. `CONNECT` 함수에 사용되는 옵션은 mysql과 동일합니다. [디비 연결](https://github.com/mysqljs/mysql#connection-options)이나 [커넥션 풀](https://github.com/mysqljs/mysql#pool-options)과 관련된 자세한 옵션은 [mysql](https://github.com/mysqljs/mysql) 사이트에서 확인할 수 있습니다.
MQL is built on node-postgres. The parameter of CONNECT function is the same as the MySQL’. You can read the detail of [connection pool](https://github.com/mysqljs/mysql#pool-options) or [connecting to DB](https://github.com/mysqljs/mysql#connection-options) on [MySQL's site](https://github.com/mysqljs/mysql).
## 간단한 쿼리
## Simple query

@@ -96,3 +100,3 @@ ```javascript

## 서브 쿼리, 조인
## Subquery, Join

@@ -121,5 +125,5 @@ ```javascript

`CONNECT`를 통해 얻은 `QUERY`는 connection pool을 이용합니다.
QUERY achieved from CONNECT uses a connection pool.
## 함수 불러오기
## Ready to be used

@@ -137,3 +141,3 @@ ```javascript

## 지원하는 헬퍼 함수
## Helper-Function

@@ -223,5 +227,5 @@ ### EQ

### 기본
### Common use
`ASSOCIATE`는 connection pool을 이용합니다.
ASSOCIATE uses Connection pool.

@@ -255,8 +259,10 @@ ```javascript

posts[0].body; // 내용
posts[0]._.user.name // 글쓴이 이름
posts[0]._.comments[0].body // 코멘트 내용
posts[0]._.comments[0]._.user.name // 댓글 작성자 이름
posts[0].body;
posts[0]._.user.name
posts[0]._.comments[0].body
posts[0]._.comments[0]._.user.name
```
`-` of `- user` refers to "Belongs to", `<` of `< user` refers to "Has many".
### Polymorphic

@@ -284,2 +290,4 @@

`p -` refers to Polymorphic + Has one, `p <` refers to Polymorphic + Has many.
### Many to many

@@ -306,3 +314,3 @@

books[0]._.authors[0].name; // 이름
books[0]._.authors[0].name;

@@ -314,11 +322,10 @@ const authors = await ASSOCIATE `

authors[0]._.books[0].name; // 책 이름
authors[0]._.books[0].name;
```
### 옵션
### Option
```javascript
/*
* 테이블명과 컬럼명이 이미 MQL 포맷과 동일하거나 ViEW 등을 이용해 잘 맞춰놨을 때에는
* ASSOCIATE에게 넘긴 문자열들을 기반으로 자동으로 테이블명과 컬럼명들을 적절히 생성합니다.
* If the tables are formed like the example below, the ASSOCIATE automatically creates the necessary table and column names for queries. the necessary names for the tables and columns for queries
* users

@@ -357,4 +364,4 @@ * - id

/*
* 위 상황에서 컬럼들을 최소화해서 가져오고 싶거나 쿼리를 추가하고 싶다면 아래와 같이할 수 있습니다.
* column에 기본키나 외래키 등을 포함시키지 않아도 적절히 ASSOCIATE 내부에서 추가하여 적절히 가져옵니다.
* You can select columns or add conditions.
* Even though you don’t select a foreign key or a primary key in the option like the below, they are included in ASSOCIATE.
* */

@@ -378,3 +385,3 @@

/*
* 만일 테이블이 아래와 같다면 옵션을 통해 매칭을 시켜주면 됩니다.
* If the names of the tables and columns does not follow the ASSOCIATE rules, you need to manually insert the correct names of the tables and columns.
* members

@@ -402,31 +409,31 @@ * - member_id

posts ${{
table: 'articles' // 데이터베이스 테이블 명이 다를 때
table: 'articles'
}}
- user ${{ // - 를 했으므로 하나를 객체로 가져옴
left_key: 'writer_id', // articles가 가진 members.member_id를 가리키는 컬럼
key: 'member_id', // members 테이블이 가진 키
table: 'members' // user의 테이블 명
- user ${{
left_key: 'writer_id',
key: 'member_id',
table: 'members'
}}
< comments ${{ // < 를 했으므로 배열로 여러개를 가져옴
key: 'article_id' // articles의 id를 가리키는 comments가 가진 컬럼
< comments ${{
key: 'article_id'
}}
- user ${{
left_key: 'writer_id', // articles가 가진 members.member_id를 가리키는 컬럼
key: 'member_id', // members 테이블이 가진 키
table: 'members' // user의 테이블 명
left_key: 'writer_id',
key: 'member_id',
table: 'members'
}}
p < likes ${{ // p < 를 이용해 하나의 likes 테이블을 통해 comments와 posts의 likes를 구현
p < likes ${{
poly_type: { parent_name: 'comments' },
key: 'parent_id'
}}
p < likes ${{ // p < 를 이용해 하나의 likes 테이블을 통해 comments와 posts의 likes를 구현
p < likes ${{
poly_type: { parent_name: 'articles' },
key: 'parent_id'
}}
x tags ${{ // x 를 통해 중간 테이블을 join 하여 다대다 관계 구현
left_key: 'id', // articles.id (articles.id = tags_articles.article_id)
left_xkey: 'article_id', // left_key와 매칭되는 tags_articles의 키 article_id
xtable: 'tags_articles', // 중간 테이블 이름
xkey: 'tag_name', // key와 매칭되는 tags_articles의 키 tag_name
key: 'name' // tags가 가진 키 (tags_articles.tag_name = tags.name)
x tags ${{
left_key: 'id',
left_xkey: 'article_id',
xtable: 'tags_articles',
xkey: 'tag_name',
key: 'name'
}}

@@ -436,7 +443,8 @@ `;

위와 같이 데이터베이스의 테이블명과 사용하고자하는 이름이 다르거나, `ASSOCIATE`가 자동생성하는 컬럼명 등과 실제 데이터베이스의 상태가 다를 경우 옵션을 이용하여 맞춰줄 수 있습니다. 그러나 대부분의 경우는 데이터베이스의 VIEW를 사용하는 것이 코드 관리에 좋습니다.
If you use VIEW in databases, it's much easier. Then, you don't need to insert all correct column and table names.
### Hook
`hook`을 이용하여 가상 컬럼이나, 정렬, 필터 등의 추가 작업을 할 수 있습니다. 자신의 안쪽 데이터들이 모두 불려진 후 실행되어 활용하기 좋습니다.
You can add virtual columns, sorting, filtering and etc by using Hook.
When all the datas are gathered below “posts”, Hook is executed.

@@ -484,7 +492,5 @@ ```javascript

`TRANSACTION`을 통해 얻은 `QUERY`는 하나의 connection을 이용합니다. `ROLLBACK`이나 `COMMIT`을 하고나면 앞서 함께 얻었던 `QUERY` 함수의 커넥션은 해제되고 더이상 사용할 수 없습니다.
## DEBUG
`MQL_DEBUG.LOG`를 `true`로 설정한 후 `QUERY`를 실행하면 콘솔에 DB로 보낸 쿼리들을 출력합니다.

@@ -491,0 +497,0 @@ ```javascript

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc