deVSner

0506 본문

카테고리 없음

0506

RudeofSun 2020. 5. 6. 12:44

db.query("SELECT user_name,text,date,channel FROM messages", (err, rows) => {

 

 

 

post: function ({ user_name, text, channel }) {
const query = "INSERT INTO messages(user_name,text,date,channel) VALUES (?,?,now(),?)";
const params = [user_name, text, channel];
return new Promise((resolve, reject) => {
db.query(query, params, (err, res) => {
if (!err) {
resolve(res);

 

왜 백틱을 써야 하나

nodejs에서 mysql문을 작성할 때 왜 백틱을 써야 하나?

https://jiwondh.github.io/2017/01/14/mysql/

 

Node.js에서 Mysql 주요 쿼리문 이용하기 | Jiwon Blog

SELECT, INSERT, UPDATE, DELETE

jiwondh.github.io

위 링크를 보면 백틱은 없고 따옴표를 썼다. 다만, 다른 변수에서 쿼리문을 넣어놓고, 그것을 이동해서 쓰고 있다. 하지만 이것은 테이블을 생성할 떄 쓰는 게 아니라 업데이트나 셀렉트 딜리트 떄이다.

아래 링크가 백틱쓰는 테이블 생성하기

https://gist.github.com/livelikeabel/909d5dc35e96e3f0bed0cd28cddcdeaf

 

Node.js 로 db다루기, application 만들기

Node.js 로 db다루기, application 만들기. GitHub Gist: instantly share code, notes, and snippets.

gist.github.com

 

 

 

 

 

왜 프로미스 함수를 써야 하나?

https://flymogi.tistory.com/entry/NodeJS%EC%97%90%EC%84%9C-MySQL-Select-data-return-%ED%95%98%EA%B8%B0

 

Node.JS에서 MySQL Select data return 하기

MySQL 연결과 단순하게 데이터를 조회하는 것은 쉽게 될 것이다. 다만, Select의 결과를 return 시켜 사용하고 싶을 때 문제가 발생한다. query = async () => { return mysql.query("select * from table", (err,..

flymogi.tistory.com

위 링크를 보면은, 콜백때문이라고 하는 거 같다

 

 

 

 

 

https://hack-cracker.tistory.com/165

 

MySQL - 자료형 CHAR와 VARCHAR의 차이점

MySQL 자료형 CHAR,VARCHAR 문자열 자료형 - CHAR, VARCHAR 자료형 의미 대응하는 범위 CHAR 고정형 문자열 255자 까지 VARCHAR 가변형 문자열 1 ~ 65535바이트 문자 수의 상한은 이용하는 문자 코드에 따라 다르..

hack-cracker.tistory.com

 

 

TEXT VS varchar

https://stackoverflow.com/questions/2023481/mysql-large-varchar-vs-text

 

MySQL: Large VARCHAR vs. TEXT?

I've got a messages table in MySQL which records messages between users. Apart from the typical ids and message types (all integer types) I need to save the actual message text as either VARCHAR or...

stackoverflow.com