@elv1bro/beanorm
v1.3.2
Published
Lightweight ORM for Node.js with automatic table creation and CRUD operations
Maintainers
Readme
BeanORM
BeanORM is a lightweight ORM library for Node.js, similar to RedBeanPHP, with automatic table and field creation, full CRUD support, relationships, and versatility.
Installation
npm install eredbeanSupported Databases
- MySQL
- PostgreSQL
- SQLite
Usage Example
import Bean from '@elv1bro/beanorm';
// MySQL/PostgreSQL
const mysqlConfig = {
type: 'mysql',
host: 'localhost',
user: 'username',
password: 'password',
database: 'mydb'
};
// SQLite
const sqliteConfig = {
type: 'sqlite',
filename: './database.sqlite'
};
const user = new Bean('user', sqliteConfig);
user.set('name', 'Alice');
user.set('email', '[email protected]');
await user.save();
const user2 = await Bean.load('user', user._id);
user2.set('name', 'Alice Smith');
await user2.save();
await user2.delete();🤖 AI Assistant Instructions
Project Metadata
We've prepared an automatically generated file PROJECT_METHODS.json with detailed information about methods and project structure.
How to Use Metadata
- Examine the
PROJECT_METHODS.jsonfile in the project root - Pay attention to class methods:
BaseModel: Basic model operationsBean: Main ORM classRepository: Data repository managementTableMetadataCache: Table metadata caching
# Quick metadata view
cat PROJECT_METHODS.jsonGenerating Metadata
To update metadata, use the command:
npm run generate-ai-metadataKey Classes and Their Methods
BaseModel
constructor(): Model initializationset(): Setting field valuessave(): Saving the modeldelete(): Deleting the model- Static methods
load()andfind()
Bean
- Extends BaseModel
- Additional methods
hasOne()andhasMany()for relationships - Support for working with different database adapters (MySQL, PostgreSQL, SQLite)
Repository
- Low-level data operations
- Methods
create(),findById(),find(),deleteById() - Raw SQL query support
TableMetadataCache
- Table structure caching
- Methods
getTableStructure(),setTableStructure() - Performance optimization
Code Study Recommendations
- Start with
Bean.js- the ORM's central class - Study
BaseModel.jsto understand basic logic - Analyze adapters in
src/adapters/ - Look at examples in the
use/directory
License
MIT License
