{"library":"sequelize","title":"Sequelize ORM","description":"Sequelize is a robust, promise-based Node.js ORM (Object-Relational Mapper) for various SQL databases including Postgres, MySQL, MariaDB, SQLite, and Microsoft SQL Server. The current stable version is 6.37.8, with version 7 actively under development in alpha. It offers features like transaction support, relations, eager/lazy loading, and read replication. The project is actively seeking new maintainers to finalize the next major release.","language":"javascript","status":"active","last_verified":"Sat Apr 18","install":{"commands":["npm install sequelize"],"cli":{"name":"sequelize","version":null}},"imports":["import { Sequelize } from 'sequelize';","import { DataTypes } from 'sequelize';","import { Model } from 'sequelize';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { Sequelize, DataTypes, Model } from 'sequelize';\n\nconst sequelize = new Sequelize({\n  dialect: 'sqlite',\n  storage: 'database.sqlite',\n  logging: false // Disable logging for cleaner output\n});\n\nclass User extends Model {}\n\nUser.init({\n  id: {\n    type: DataTypes.INTEGER,\n    autoIncrement: true,\n    primaryKey: true\n  },\n  username: {\n    type: DataTypes.STRING,\n    allowNull: false,\n    unique: true\n  },\n  email: {\n    type: DataTypes.STRING,\n    allowNull: false,\n    unique: true\n  }\n}, {\n  sequelize,\n  modelName: 'User'\n});\n\nasync function run() {\n  try {\n    await sequelize.authenticate();\n    console.log('Connection has been established successfully.');\n\n    await sequelize.sync({ force: true }); // This will drop existing tables\n    console.log('All models were synchronized successfully.');\n\n    const jane = await User.create({ username: 'JaneDoe', email: 'jane.doe@example.com' });\n    console.log(`Created user: ${jane.username}`);\n\n    const users = await User.findAll();\n    console.log('All users:', users.map(u => u.toJSON()));\n\n  } catch (error) {\n    console.error('Unable to connect to the database:', error);\n  } finally {\n    await sequelize.close();\n  }\n}\n\nrun();","lang":"typescript","description":"This quickstart demonstrates how to connect to an SQLite database, define a User model, synchronize the schema, create a new user, and fetch all users. It uses `sequelize.sync({ force: true })` for simplicity, which will drop and re-create tables on each run.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}