3-1.lowdb,lodash 사용 과정 및 오류 해결
1.lowdb 란
JSON이라는 파일 형식을 사용하여 데이터를 저장하는 간단한 데이터 베이스이며
선언 방식입니다.(버전 4 버전으로 설치하였습니다 5 버전으로 설치해보았지만 다운그레이드를 하여 성공을 하였습니다)
import lowdb from 'lowdb'
import LocalStorage from 'lowdb/adapters/LocalStorage'
const adapter =new LocalStorage('todo-app') //DB
this.db = lowdb(adapter)
사용하는 방법
createTodo(title){
const newTodo = {
id:cryptoRandomString({length: 10 }),
title,
createdAt: new Date(),
updatedAt: new Date(),
done:false
}
this.db
.get('todos') //lodash
.push(newTodo) //lodash
.write() //마지막은 항상 write 를 붙여줘야합니다
}
요약본
1.3일 동안 버전 그레이드로 고생했습니다.. 버전의 중요성을 알았고
2. 아직은 실력이 부족하다는 것을 알았습니다.
참조할 사이트
Lodash
_.defaults({ 'a': 1 }, { 'a': 3, 'b': 2 });_.partition([1, 2, 3, 4], n => n % 2);DownloadLodash is released under the MIT license & supports modern environments. Review the build differences & pick one that’s right for you.InstallationIn
lodash.com
https://github.com/typicode/lowdb
GitHub - typicode/lowdb: Simple to use local JSON database (supports Node, Electron and the browser)
Simple to use local JSON database (supports Node, Electron and the browser) - GitHub - typicode/lowdb: Simple to use local JSON database (supports Node, Electron and the browser)
github.com