Coder Social home page Coder Social logo

redbean's Introduction

RedBean

RedBean is an easy to use ORM tool that stores beans directly in the database and creates all tables and columns required on the fly. On the other hand it allows plain SQL to search the database. In fact RedBean is some sort of combination between document oriented database tools like mongoDB or couchDB and traditional relational database systems like MySQL. It offers the best of both worlds: SQL and no-SQL. You work with no-SQL if you interact with objects will you simply turn the switch and work with SQL if you want to do some typical database tasks like searching or quikly grabbing something out of the data store with specially crafted SQL. RedBean also has excellent performance because it can freeze the database schema which means it no longer scans schemas.

Databases Supported

RedBean supports MySQL (InnoDB and MyISAM), MySQL strict, PostgreSQL and SQLite. There are specific database plugins though.

Example

How we store a book object with RedBean:

$book = $redbean->dispense("book");
$book->author = "Santa Claus";
$book->title = "Secrets of Christmas";
$id = $redbean->store( $book );

Yep, it's that simple.

CRUD

//Create a Bean $book = $redbean->dispense("book");

//Store a Bean $book->author = "Santa Claus"; $book->title = "Secrets of Christmas"; $id = $redbean->store( $book );

//Load a Bean $aBookFromSanta = $redbean->load( "book", $id );

//Trash a Bean $redbean->trash( $book );

Finding Beans

This is where most ORM layers simply get it wrong. An ORM tool is only useful if you are doing object relational tasks. Searching a database has never been a strong feature of objects; but SQL is simply made for the job. In many ORM tools you will find statements like: $person->select("name")->where("age","20") or something like that. I found this a pain to work with. Some tools even promote their own version of SQL. To me this sounds incredibly stupid. Why should you use a system less powerful than the existing one? This is the reason that RedBean simply uses SQL as its search API.

The easiest way to search a bean using RedBean is to use the Find plugin. This plugin is enabled by default; works for most databases and accepts plain old SQL. Here is an example:

$actors = Finder::where("page", " name LIKE :str ", array(":str"=>'%more%'));

Features

  • Easy CRUD.
  • Easy ways to convert beans in full fledged domain models.
  • Supports many databases.
  • Easy integration in Zend Framework, Code Igniter and Kohana (see tutorials).
  • Very flexible, works with predefined schemas as well.
  • Excellent performance (thanks to freeze-mode).

redbean's People

Contributors

dontneedgithubaccount avatar seanhess avatar

Stargazers

Michael Wills avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.