
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
MinORM is a high-performance ORM built on top of Node MySQL2 that is a continuation of Node MySQL-Native. Also MinORM uses Squel library as Query Builder
It's really lightweight, provide simple solutions that just works without a lot of configurations.
Main features:
If you are tired by highweight ORMs like Bookshelf or Sequelize, and want just some basic functionality from it - MinORM can be a good start point. MinORM also have build-in Migrations module that you can use.
npm install --save minorm
import {createManager} from 'minorm'
export const manager = createManager({
//options like for MySQL2 pool creation
})
manager.connect()
export const PostsRepo = {
...manager.getRepository('posts'),
async getPostsFromUser(id) {
const postQuery = this.startQuery('post')
.include('post', 'creator_id')
.tryInclude('creator', 'avatar_id')
.where('post.creator_id = ?', id)
.criteria({
'post.title': {
$not: 'Bad title'
}
})
const [result] = await manager.nestQuery(postQuery)
//Or:
const result = await postQuery.execute(true)
return result.map(({post, creator}) => ({
...post,
creator
}))
}
}
connect()
- connect to databasegetRepository(tableName)
- returns a RepositorygetConnection()
- returns MySQL Connection from poolgetLogger()
returns logger used for managergetPool()
- returns Connection poolclear()
- clear connection, Repositories and MetadatagetMetadataManager()
- returns Metadata managersetMetadataManager(manager)
- replace Metadata manager with cachablequery(query: SqeulQuery)
- execute query in poolnestQuery(query: SquelQuery)
- execute query and return result as [{table1: {feilds}, table2: {}}, {table1: {fiedls}}]
etcstartQuery()
- returns a wrapped Squel Query BuilderextendRepository(tableName, callback)
- If you want to extend Repository by some methods you can follow two ways:
extendRepository
method, that receive original repo object and must return new repo object. Can be used to override native methods like hydrate
etc.MinORM uses Repositories for working with tables. One table == one Repository. It has a lot of useful methods like:
find(id)
- search single record in DB by id and wrap it as the modelfindOneBy(criteria)
- search single record in DB by criteria.findBy(criteria, orderBy = {}, limit, offset)
- search records by criteria with limits and offsetsstartQuery(alias = null)
- create select Querycreate(data)
- adds Model methods to any object with structurehydrate(data, isFetched)
- helper method that attach Model methods to any object and accept argument that promise that this object is fetched from DB without changes.getMetadata()
- returns object with all table columnsupdate(selector: number| Criteria, changes: Object): Promise<affectedRows>
- update single or many rows in tableremove(selector: number| Criteria): Promise<affectedRows>
- remove single or many rows in tableCriteria is a plain object with key
is a column name, value
is a simple string, number, etc or object with operator like $in
, $not
, $like
and $notIn
.
MinORM don't have any column mappers and/or hydrators. So Models is just result from mysql2
qeury, with assigned non-enumerable methods:
save()
- UPDATE or INSERT data to DBpopulate(data)
- populate data to modelremove()
- remove model in DBcreateManager
supports second parameter as logger, you can choose logger to use it can be simple winston
or any other logger.
MinORM have ability to write your own Migrations and initializers. For example:
import {createSchemaTool} from 'minorm'
const schemaTool = createSchemaTool(manager)
schemaTool.setSchemaInit({//It's also migration
up(schema) {
schema.table('users', table => {
table.id()
table.column('login').notNull()
table.column('password').notNull()
table.createdAndModified()
})
schema.table('posts', table => {
table.id()
table.column('title').notNull()
table.column('body').text()
table.column('creator_id').int().unsigned()
table.createdAndModified()
table.ref('creator_id', 'users', 'id')
})
},
down(schema) {
schema.dropTable('posts')
schema.dropTable('users')
}
})
schemaTool.getMigrationManager().addMigration(
'2016-11-16 19:01:18',
{
up(schema) {
schema.use('posts', table => {
table.index('title')
})
},
down(schema) {
schema.use('users', table => {
table.dropIndex('IDX_title')
})
}
}
)
schemaTool.initSchema().then(() => {
console.log('Database inited')
})
When you write Migrations you don't need to worry about async things. All references will be added after all tables are created. So in case of cross-relations between tables you will not receive any problems.
FAQs
MinORM - Light high-performance ORM for MySQL
The npm package minorm receives a total of 48 weekly downloads. As such, minorm popularity was classified as not popular.
We found that minorm demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.