# SQLite를 도큐먼트DB로 사용하기

> Clean Markdown view of GeekNews topic #3271. Use the original source for factual precision when an external source URL is present.

## Metadata

- GeekNews HTML: [https://news.hada.io/topic?id=3271](https://news.hada.io/topic?id=3271)
- GeekNews Markdown: [https://news.hada.io/topic/3271.md](https://news.hada.io/topic/3271.md)
- Type: news
- Author: [xguru](https://news.hada.io/@xguru)
- Published: 2020-11-28T10:15:34+09:00
- Updated: 2020-11-28T10:15:34+09:00
- Original source: [dgl.cx](https://dgl.cx/2020/06/sqlite-json-support)
- Points: 7
- Comments: 6

## Topic Body

- SQLite의 Generated Columns 와 JSON 관련 함수를 사용해서 Document DB처럼 사용하는 방법

- GENERATED ALWAYS 와 json_extract 를 조합

> CREATE TABLE t ( body TEXT, d INT GENERATED ALWAYS AS (json_extract(body, '$.d')) VIRTUAL);

> INSERT INTO t VALUES(json('{"d":"42"}'));

> SELECT * FROM t WHERE d = 42;

{"d":"42"}|42

## Comments



### Comment 3638

- Author: nicewook
- Created: 2020-11-30T09:38:57+09:00
- Points: 1

이렇게도 사용가능할까요? RDBMS의 장점을 취하면서도 마이너한 필드 추가, 변경의 NoSQL 확장성을 가져갈 수 있을것 같은데요

1. 일단은 SQLite 를 사용한다.

2. 필드를 추가해야 할 경우에 이처럼 도큐먼트 DB로 사용한다.

### Comment 3644

- Author: galadbran
- Created: 2020-11-30T13:53:24+09:00
- Points: 1
- Parent comment: 3638
- Depth: 1

언급된 제너레이티드 컬럼과 동일하지는 않을 수 있는데, postgresql, mysql 도 이미 json 타입 컬럼과 해당 타입에 대한 쿼리가 제공되어서 비슷하게 사용할 수는 있을 것 같습니다.

### Comment 3640

- Author: xguru
- Created: 2020-11-30T09:48:49+09:00
- Points: 1
- Parent comment: 3638
- Depth: 1

말씀하신대로 커스텀한 사용자 필드 추가나 그런 용도로 사용할수 있을거 같아요.

### Comment 3632

- Author: ffdd270
- Created: 2020-11-29T18:25:05+09:00
- Points: 1

으음.. 도큐먼트 DB중에는 SQLite처럼 임베디드 타겟으로 나온 DB가 없을까용? SQLite가 근본이 SQL이라서 부담감이 있어서요 OTL. MongoDB의 Lite 버전. MangoDB라던가(...)

### Comment 3639

- Author: xguru
- Created: 2020-11-30T09:46:53+09:00
- Points: 2
- Parent comment: 3632
- Depth: 1

단순 키밸류용으로는 RocksDB https://github.com/facebook/rocksdb

말씀하신것처럼 도큐먼트DB용으로는 UnQLite https://unqlite.org/

정도가 빠르고 쓰기편하다고 합니다.

### Comment 3658

- Author: ffdd270
- Created: 2020-12-01T14:07:16+09:00
- Points: 1
- Parent comment: 3639
- Depth: 2

오오. 감사합니당. 이제 SQLite 말고 얘네들도 한번씩 써봐야 겠네요.
