eveningkid / denodb

MySQL, SQLite, MariaDB, PostgreSQL and MongoDB ORM for Deno

Home Page:https://eveningkid.com/denodb-docs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error on use VanillaJS

DrMcHack opened this issue · comments

Error in SQLTranslator.translateToQuery method:

error: Uncaught (in promise) ReferenceError: Buffer is not defined
        } else if (Buffer.isBuffer(val)) {
               ^
    at escapeFn (https://raw.githubusercontent.com/Zhomart/dex/930253915093e1e08d48ec0409b4aee800d8bd0c/lib-dyn/query/string.js:44:16)
    at Client_SQLite3.finalEscape [as _escapeBinding] (https://raw.githubusercontent.com/Zhomart/dex/930253915093e1e08d48ec0409b4aee800d8bd0c/lib-dyn/query/string.js:18:12)
    at https://raw.githubusercontent.com/Zhomart/dex/930253915093e1e08d48ec0409b4aee800d8bd0c/lib-dyn/client.js:153:19
    at String.replace (<anonymous>)
    at Client_SQLite3._formatQuery (https://raw.githubusercontent.com/Zhomart/dex/930253915093e1e08d48ec0409b4aee800d8bd0c/lib-dyn/client.js:145:16)
    at https://raw.githubusercontent.com/Zhomart/dex/930253915093e1e08d48ec0409b4aee800d8bd0c/lib-dyn/interface.js:14:28
    at Array.map (<anonymous>)
    at Builder.Target.toQuery (https://raw.githubusercontent.com/Zhomart/dex/930253915093e1e08d48ec0409b4aee800d8bd0c/lib-dyn/interface.js:13:8)
    at Builder.toString (https://raw.githubusercontent.com/Zhomart/dex/930253915093e1e08d48ec0409b4aee800d8bd0c/lib-dyn/query/builder.js:70:17)
    at SQLTranslator.translateToQuery (https://deno.land/x/denodb@v1.0.40/lib/translators/sql-translator.ts:225:25)

https://doc.deno.land/deno/stable/~/Deno.Buffer is deprecated. So please use https://deno.land/std/io/buffer.ts instead, to fix this error.

Solution:

import {Buffer} from "https://deno.land/std/io/buffer.ts";

window.Buffer = Buffer;

Buffer.isBuffer = function(obj) {
  if (obj === null || typeof obj === 'undefined') {
    return false;
  }

  return !!(obj.constructor && obj.constructor.isBuffer && obj.constructor.isBuffer(obj));
}

You save my life.