Barebone\Activerecord

An Active Record is a software design pattern used in object-relational mapping (ORM). It simplifies the process of working with databases by providing a layer of abstraction between your application code and the underlying SQL.

Here's a breakdown of the concept:

1. Object-Relational Mapping (ORM):

  • An ORM bridges the gap between object-oriented programming languages and relational databases (which store data in tables).
  • It allows you to interact with database tables using objects that represent real-world entities (like users, products, orders).

2. Active Record Pattern:

  • This pattern focuses on creating objects that directly map to database tables.
  • Each object instance corresponds to a single row in the table.
  • The object's attributes (like username, product name) mirror the table's columns.

Benefits of Active Record:

  • Reduced Code: You can interact with databases using object-oriented syntax, eliminating the need to write raw SQL statements for basic CRUD (Create, Read, Update, Delete) operations.
  • Improved Readability: Code becomes more readable and maintainable as it focuses on object manipulation.
  • Reduced Errors: ORM handles potential SQL injection vulnerabilities by providing a safer way to interact with the database.
  • Automatic Data Mapping: The ORM automatically maps object attributes to database columns, saving you manual configuration effort.

Example (Simplified):

Imagine a User object in a Barebone application with an Active Record implementation.

  • You might have attributes like name, email, and password in the User object.
  • These attributes would map to corresponding columns in a User table in your database.

Active Record Frameworks:

  • Barebone Framework offers built-in Active Record implementations. Just connect to a database and click 'Create database models'
  • These frameworks provide additional features like data validation, relationships between models, and automatic schema generation based on your object definitions.

Overall, Active Record is a powerful pattern that streamlines database interactions, making your web applications more efficient and easier to develop and maintain.

  • Database\Barebone_me\Activerecords\customer

    Database\Barebone_me\Activerecords\customer extends Barebone\Activerecord
    • [P] $id : mixed
    • [P] $username : mixed
    • [P] $password : mixed
    • [P] $email : mixed
    • [P] $created : mixed
    • Barebone\Activerecord

      Barebone\Activerecord
      • [P] $tablename : string
      • [P] $primary_key : string
      • [P] $pdo : Barebone\Database\Connectors\PDO
      • [P] $debug : bool
      • [P] $joins : array
      • [P] $selected_columns : array
      • [M] __construct( mixed $data ) : void
      • [M] _throw_exception( PDOStatement $stmt, string $sql ) : void
      • [M] _pdo_debug_StrParams( $stmt ) : void
      • [M] is_protected_propertie( string $propertie ) : void
      • [M] debug( bool $debug ) : Barebone\Activerecord
      • [M] create( mixed $data ) : void
      • [M] __call( string $name, array $arguments ) : void
      • [M] __set( string $name, string $value ) : void
      • [M] __serialize() : array
      • [M] __unserialize( array $data ) : void
      • [M] escape( string $value ) : void
      • [M] propertie_exists( string $propertie ) : void
      • [M] get_columns() : void
      • [M] get_column( $columnname ) : void
      • [M] get_primary_key() : void
      • [M] set_data( mixed $data, bool $clean, array $protected ) : void
      • [M] get_data() : array
      • [M] get_by_id( int $id ) : void
      • [M] escapeIdentifier( string $identifier ) : string
      • [M] escapeOrderBy( array|string $order ) : string
      • [M] fetch_all( array $options ) : void
      • [M] all( array $options ) : void
      • [M] first() : void
      • [M] last() : void
      • [M] find( mixed $args ) : void
      • [M] find_by_sql( string $sql, array $params, string $objName ) : void
      • [M] find_in( string $key, array $array, string $type, bool $quote ) : void
      • [M] insert() : void
      • [M] update() : void
      • [M] save() : mixed
      • [M] delete() : void
      • [M] count( string $where ) : int
      • [M] still_exists() : bool
      • [M] is_valid( array $validators ) : void
      • [M] getProperties( bool $withdata ) : stdClass
      • [M] get_schema_path() : string
      • [M] validate_input( mixed $data ) : array
      • [M] drop_column( string $columnname ) : void
      • [M] to_grid( array $options, array $columns, Barebone\Controller $controller ) : void
        ↳ trait: Barebone\Activerecord\HtmlRecordRendering
      • [M] render_form( Barebone\Form\Decorators\DecoratorInterface $decorator, array $form_attr, array $options ) : void
        ↳ trait: Barebone\Activerecord\HtmlRecordRendering
      • [M] get_form( array $form_attr ) : void
        ↳ trait: Barebone\Activerecord\HtmlRecordRendering
      • [M] to_data_table( Barebone\View $view, array $options, array $formatter ) : void
        ↳ trait: Barebone\Activerecord\HtmlRecordRendering
      • [M] get_selected_columns() : void
        ↳ trait: Barebone\Activerecord\HtmlRecordRendering
      • [M] create_join_strings() : string
        ↳ trait: Barebone\Activerecord\ActiverecordJoinTrait
      • [M] join( Barebone\Activerecord $foreign_table, string $primary_key, string $foreign_key, string $join_type ) : void
        ↳ trait: Barebone\Activerecord\ActiverecordJoinTrait
      • [M] left_join( Barebone\Activerecord $foreign_table, string $primary_key, string $foreign_key ) : void
        ↳ trait: Barebone\Activerecord\ActiverecordJoinTrait
      • [M] right_join( Barebone\Activerecord $foreign_table, string $primary_key, string $foreign_key ) : void
        ↳ trait: Barebone\Activerecord\ActiverecordJoinTrait
      • [M] inner_join( Barebone\Activerecord $foreign_table, string $primary_key, string $foreign_key ) : void
        ↳ trait: Barebone\Activerecord\ActiverecordJoinTrait
      • [M] outer_join( Barebone\Activerecord $foreign_table, string $primary_key, string $foreign_key ) : void
        ↳ trait: Barebone\Activerecord\ActiverecordJoinTrait
      • [M] toArray() : void
        ↳ trait: Barebone\Activerecord\ActiverecordDataConversionTrait
      • [M] toObject() : void
        ↳ trait: Barebone\Activerecord\ActiverecordDataConversionTrait
      • [M] toJSON( bool $withdata ) : string|bool
        ↳ trait: Barebone\Activerecord\ActiverecordDataConversionTrait
      • [M] toTable( array $options ) : Barebone\HTML\TTable
        ↳ trait: Barebone\Activerecord\ActiverecordDataConversionTrait
      • [M] getHash() : string
        ↳ trait: Barebone\Activerecord\ActiverecordDataConversionTrait