Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
@datawrapper/orm
Advanced tools
Readme
A database abstraction layer for Datawrapper
Usage:
Add the package to your repository using:
npm i --save "@datawrapper/orm"
In your app you need to initialize the ORM before you can do anything else with it. It's a good idea to do this in your apps main entry point:
const orm = require('@datawrapper/orm');
orm.init({
dialect: 'mysql',
host: '127.0.0.1',
port: 3306,
user: '...',
password: '...',
database: '...'
});
Then you can load the models using:
const { Chart, User } = require('@datawrapper/orm/models');
Note that this will initialize the entire model, which assumes that your database user has access to all the database tables. If this is not the case you can load individual models using
const User = require('@datawrapper/orm/models/User');
The ORMs functionality can be extended with plugins. This is needed, for example, when new database tables are needed. The plugin API follows the convention of plugins in datawrapper/api.
A simple ORM plugin that does nothing looks like this:
/* config.js */
plugins: {
'my-orm-plugin': {
my_name: 'Steve'
}
}
/* orm.js */
module.exports = {
register: async (ORM, config) => {
console.log(`Hi I am ${config.my_name}!`)
// logs "Hi I am Steve!" on registration
}
}
There are 2 interesting properties on the ORM
object that help with plugin access.
ORM.plugins
is an object with all configured plugins. They are not registered by default. Since standard Models
are not defined after ORM.init()
either, it wouldn't make sense to do that for plugins.This is how you register a plugin:
await ORM.init()
const { plugins } = ORM
const MyORMPlugin = require(plugins['my-orm-plugin'].requirePath)
await MyORMPlugin.register(ORM, plugins['my-orm-plugin'])
This method is very useful for tests where you only need a special plugin. There is also a helper method to register all plugins. It is in functionality similar to requiring all models with require('@datawrapper/orm/models')
.
ORM.registerPlugins
will register all plugins.await ORM.init()
await ORM.registerPlugins()
FAQs
A database abstraction layer for Datawrapper
The npm package @datawrapper/orm receives a total of 51 weekly downloads. As such, @datawrapper/orm popularity was classified as not popular.
We found that @datawrapper/orm demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 21 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.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.