0.0.21 • Published 7 months ago

@letsscrapedata/db v0.0.21

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
7 months ago

Please get help and discuss how to scrape a website on the discord server, which can respond quickly. It is better to submit issues on github for better tracking.

Features

This package is mainly used by LetsScrapeData App to access different databases using a unified interface. Compared to comprehensive knex, this package is simple to use and more suitable for developers who like to use SQL statements and JSON objects directly.

  • Supported databases: mysql, sqlite (more to come)
  • DQL: select, selectColumns
  • DML: delete, insert, insertObjects, update, updateByObject
  • DDL: execOneDdlSql, execSqlScript
  • transanction: begin, commit, rollback
  • sqlite: support "concurrent" transactions by executing transactions one by one
  • Automatic camelize and decamel conversion
  • logging: when a transaction exceeds the set time, print the log

Install

npm install @letsscrapedata/db

Examples

import { Db, MysqlConnectCfg } from "@letsscrapedata/db";

const connCfg: MysqlConnectCfg = {
  dbType: "mysql",
  host: "127.0.0.1",
  user: "username",
  password: "password",
  database: "db1"
};

const db = new Db("mysql");
await db.connect(connCfg);

const accounts= [ {userName: "Louis", age: 34, gender: "male"} ];

await db.insertObjects("account", accounts);
// the same
await db.insert("INSERT INTO account(user_name, age, gender) VALUES(?, ?, ?)", ["Louis", 34, "male"]);

let records = await db.select("SELECT user_name AS userName, gender FROM account WHERE age > ?", [30])
// the same(camelCaseFlag: default true)
records = await db.selectColumns(["user_name", "gender"], "account", "age > ?", [30]);

await db.close();
0.0.20

7 months ago

0.0.21

7 months ago

0.0.10

8 months ago

0.0.11

8 months ago

0.0.12

8 months ago

0.0.13

7 months ago

0.0.14

7 months ago

0.0.15

7 months ago

0.0.9

9 months ago

0.0.16

7 months ago

0.0.8

9 months ago

0.0.17

7 months ago

0.0.18

7 months ago

0.0.19

7 months ago

0.0.7

10 months ago

0.0.5

1 year ago

0.0.6

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago