Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
A Knex little more factory of SQL query builder, with auto-generated type-safe tables accessor for Node.js
A Knex little more factory of SQL query builder, with auto-generated type-safe tables accessor via TypeScript compiler API for Node.js.
npm install kmore knex
# Then add one of the following:
npm install pg
npm install mssql
npm install oracle
npm install sqlite3
import { Config } from 'kmore'
// connection config
export const config: Config = {
client: 'pg',
// connection: process.env.PG_CONNECTION_STRING,
connection: {
host: 'localhost',
user: 'postgres',
password: 'foo',
database: 'db_ci_test',
},
}
// Define Types of tables
export interface TbListModel {
tb_user: User
tb_user_detail: UserDetail
}
export interface User {
uid: number
name: string
ctime: Date | 'now()'
}
export interface UserDetail {
uid: number
age: number
address: string
}
/**
* Initialize db connection and generate type-safe tables accessor (name and builder)
* will get
* - db.dbh : the connection instance of knex
* eg. db.dbh<OtherType>('tb_other').select()
* - db.tables : tables name accessor containing table key/value paris
* - db.rb : tables builder accessor,
* eg. db.rb.user() => Knex.QueryBuilder<{id: number, name: string}>
*/
const db = kmore<TbListModel>(config)
await db.dbh.schema
.createTable('tb_user', (tb) => {
tb.increments('uid')
tb.string('name', 30)
tb.timestamp('ctime', { useTz: false })
})
.createTable('tb_user_detail', (tb) => {
tb.integer('uid')
tb.foreign('uid')
.references('tb_user.uid')
.onDelete('CASCADE')
.onUpdate('CASCADE')
tb.integer('age')
tb.string('address', 255)
})
.catch((err: Error) => {
assert(false, err.message)
})
// auto generated accessort tb_user() and tb_user_detail() on db.rb
const { tb_user, tb_user_detail } = db.rb
await tb_user()
.insert([
{ name: 'user1', ctime: new Date() }, // ms
{ name: 'user2', ctime: 'now()' }, // μs
])
.then()
await tb_user_detail()
.insert([
{ uid: 1, age: 10, address: 'address1' },
{ uid: 2, age: 10, address: 'address1' },
])
.returning('*')
.then()
const { tables: t, rb } = db
await rb.tb_user()
.select(`${t.tb_user}.uid`, `${t.tb_user}.name`)
.innerJoin(
t.tb_user_detail,
`${t.tb_user}.uid`,
`${t.tb_user_detail}.uid`,
)
.where(`${t.tb_user}.uid`, 1)
.then((rows) => {
assert(rows && rows.length === 1 && rows[0].uid === 1)
return rows
})
.catch((err: Error) => {
assert(false, err.message)
})
// drop table
await db.dbh.raw(`DROP TABLE IF EXISTS "${tb}" CASCADE;`).then()
// disconnect
await db.dbh.destroy()
10.4.0 (2021-06-29)
FAQs
A SQL query builder based on knex with powerful TypeScript type support
The npm package kmore receives a total of 27 weekly downloads. As such, kmore popularity was classified as not popular.
We found that kmore demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.