All Projects → cyjake → Leoric

cyjake / Leoric

Licence: bsd-3-clause
👑 JavaScript ORM for MySQL, PostgreSQL, and SQLite.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Leoric

Peewee Async
Asynchronous interface for peewee ORM powered by asyncio
Stars: ✭ 607 (+545.74%)
Mutual labels:  orm, mysql, postgresql
Bookshelf
A simple Node.js ORM for PostgreSQL, MySQL and SQLite3 built on top of Knex.js
Stars: ✭ 6,252 (+6551.06%)
Mutual labels:  orm, mysql, postgresql
Mormot
Synopse mORMot ORM/SOA/MVC framework
Stars: ✭ 607 (+545.74%)
Mutual labels:  orm, mysql, postgresql
Go Sqlbuilder
A flexible and powerful SQL string builder library plus a zero-config ORM.
Stars: ✭ 539 (+473.4%)
Mutual labels:  orm, mysql, postgresql
Chloe
A lightweight and high-performance Object/Relational Mapping(ORM) library for .NET --C#
Stars: ✭ 1,248 (+1227.66%)
Mutual labels:  orm, mysql, postgresql
Typeorm
ORM for TypeScript and JavaScript (ES7, ES6, ES5). Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.
Stars: ✭ 26,559 (+28154.26%)
Mutual labels:  orm, mysql, postgresql
Sequelize
An easy-to-use and promise-based multi SQL dialects ORM tool for Node.js
Stars: ✭ 25,422 (+26944.68%)
Mutual labels:  orm, mysql, postgresql
Openrecord
Make ORMs great again!
Stars: ✭ 474 (+404.26%)
Mutual labels:  orm, mysql, postgresql
Diesel
A safe, extensible ORM and Query Builder for Rust
Stars: ✭ 7,702 (+8093.62%)
Mutual labels:  orm, mysql, postgresql
Xorm
Simple and Powerful ORM for Go, support mysql,postgres,tidb,sqlite3,mssql,oracle, Moved to https://gitea.com/xorm/xorm
Stars: ✭ 6,464 (+6776.6%)
Mutual labels:  orm, mysql, postgresql
Lithium
Easy to use C++17 HTTP Server with no compromise on performances. https://matt-42.github.io/lithium
Stars: ✭ 523 (+456.38%)
Mutual labels:  orm, mysql, postgresql
Pop
A Tasty Treat For All Your Database Needs
Stars: ✭ 1,045 (+1011.7%)
Mutual labels:  orm, mysql, postgresql
Qb
The database toolkit for go
Stars: ✭ 524 (+457.45%)
Mutual labels:  orm, mysql, postgresql
Prisma
Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite & MongoDB (Preview)
Stars: ✭ 18,168 (+19227.66%)
Mutual labels:  orm, mysql, postgresql
Denodb
MySQL, SQLite, MariaDB, PostgreSQL and MongoDB ORM for Deno
Stars: ✭ 498 (+429.79%)
Mutual labels:  orm, mysql, postgresql
Lucid
AdonisJS official SQL ORM. Supports PostgreSQL, MySQL, MSSQL, Redshift, SQLite and many more
Stars: ✭ 613 (+552.13%)
Mutual labels:  orm, mysql, postgresql
Antdata.orm
特色:vs插件或者t4一键生成entity 支持配置非物理外键。分离linq转sql引擎(原生linq非扩展)和执行dal功能,支持异步,支持netcore2.0
Stars: ✭ 428 (+355.32%)
Mutual labels:  orm, mysql, postgresql
Jooq
jOOQ is the best way to write SQL in Java
Stars: ✭ 4,695 (+4894.68%)
Mutual labels:  orm, mysql, postgresql
Smartsql
SmartSql = MyBatis in C# + .NET Core+ Cache(Memory | Redis) + R/W Splitting + PropertyChangedTrack +Dynamic Repository + InvokeSync + Diagnostics
Stars: ✭ 775 (+724.47%)
Mutual labels:  orm, mysql, postgresql
Treefrog Framework
TreeFrog Framework : High-speed C++ MVC Framework for Web Application
Stars: ✭ 885 (+841.49%)
Mutual labels:  orm, mysql, postgresql

Leoric

NPM Downloads NPM Version Build Status Coverage Status

Leoric is an object-relational mapping for Node.js, which is heavily influenced by Active Record of Ruby on Rails. See the documentation for detail.

Usage

Assume the tables of posts, users, and comments were setup already. We may declare the models as classes by extending from the base class Bone of Leoric. After the models are connected to the database, the columns of the tables are mapped as attributes, the associations are setup, feel free to start querying.

const { Bone, connect } = require('leoric')

// define model
class Post extends Bone {
  static describe() {
    this.belongsTo('author', { Model: 'User' })
    this.hasMany('comments')
  }
}

async function main() {
  // connect models to database
  await connect({ host: 'example.com', models: [ Post ], /* among other options */ })

  // CRUD
  await Post.create({ title: 'New Post' })
  const post = await Post.findOne({ title: 'New Post' })
  post.title = 'Untitled'
  await post.save()

  // or UPDATE directly
  await Post.update({ title: 'Untitled' }, { title: 'New Post' })

  // find with associations
  const post = await Post.findOne({ title: 'New Post' }).with('comments')
  console.log(post.comments) // => [ Comment { id, content }, ... ]
}

If table structures were intended to be maintained in the models, Leoric can be used as a table migration tool as well. We can just define attributes in the models, and call realm.sync() whenever we are ready.

const { BIGINT, STRING } = Bone.DataTypes;
class Post extends Bone {
  static attributes = {
    id: { type: BIGINT, primayKey: true },
    email: { type: STRING, allowNull: false },
    nickname: { type: STRING, allowNull: false },
  }
}

const realm = new Realm({ models: [ Post ] });
await realm.sync();

Syntax Table

JavaScript SQL
Post.create({ title: 'New Post' }) INSERT INTO posts (title) VALUES ('New Post')
Post.all SELECT * FROM posts
Post.find({ title: 'New Post' }) SELECT * FROM posts WHERE title = 'New Post'
Post.find(42) SELECT * FROM posts WHERE id = 42
Post.order('title') SELECT * FROM posts ORDER BY title
Post.order('title', 'desc') SELECT * FROM posts ORDER BY title DESC
Post.limit(20) SELECT * FROM posts LIMIT 0, 20
Post.update({ id: 42 }, { title: 'Skeleton King' }) UPDATE posts SET title = 'Skeleton King' WHERE id = 42
Post.remove({ id: 42 }) DELETE FROM posts WHERE id = 42

A more detailed syntax table may be found at the documentation site.

Contributing

There are many ways in which you can participate in the project, for example:

If you are interested in fixing issues and contributing directly to the code base, please see the document How to Contribute, which covers the following:

  • The development workflow, including debugging and running tests
  • Coding guidelines
  • Submitting pull requests
  • Contributing to translations

Related Projects

If developing web applications with egg framework, it's highly recommended using the egg-orm plugin.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].