Giter Club home page Giter Club logo

prestashopsimpledbtables's Introduction

Prestashop Db tables

Installation

composer require cerki/simple_prestashop_persistence

Example usage

<?php
use SimpleTables\Db\PrestaTable;
class MyExampleTable extends PrestaTable{
  function getTableName(){
    return "mytablename";
  }

  function getTableColumns(){
    return [
    "id" => "INTEGER NOT NULL PRIMARY KEY",
    "myfield1" => "VARCHAR(255)",
    "myfield2" => "INTEGER NOT NULL"
    ];
  }
}
function my_function(){
 $mytable = new MyExampleTable(); // NOTE you should have prestashop Db class loaded
                                  // so either do it in module/controller or import config.inc.php
 $mytable->saveExistingColumns([
                              "myfield1" => "somedata1"
                              "myfield2" => 2
                              ]);
 $mytable->getBy(["myfield1" => "somedata1"]
 // ["myfield2" => "ASC"] second argument - sorting
 ); // should return [["id" => 1,"myfield1" => "somedata1","myfield2"=>"somedata2"]]
}

Updating columns

You can update existing columns by calling

$mytable->updateTableWithColumns([
                                "myfield3" => "BOOL" // add a new field
                                "myfield1" => "VARCHAR(1024) NOT NULL" // update existing field
                                ]); 

Method list

function updateTableWithColumns($columns);
function dropTable();
function deleteBy($data); // Similar to getBy
function getBy($data,$order=NULL);
function saveExistingColumns($assoc_array); // NOTE saves a new instance if primary key is not included or doesn't exists, otherwise updates entry
function save($item) // normal insert throws error if primary key exists 
function getAll();
function getColumnNames();

Technicalities

  • It Checks if table exists and creates a new one if it doesn't on each new call
  • It creates table with utf8 utf8_unicode_ci collation

prestashopsimpledbtables's People

Contributors

p2d0 avatar

Watchers

 avatar

Forkers

johnulist

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.