DATABASE DOCUMENTATION

This documentation is only for the database. Limonade has it's own documentation.

Be sure to require database.php on the pages you want to use database.php functions.

require_once("path/to/.../lib/database.php");

DATA SETS & GROUPS

SET(column, value);
SET(column, value, type);

SET("col_name", "cheese");               //  col_name = 'text'
SET("col_name", 2);                      //  col_name = 2
SET("col_name", 3.14);                   //  col_name = 3.14
SET("col_name", true);                   //  col_name = true
SET("col_name", null);                   //  col_name = null
SET("col_name", 2, "string");            //  col_name = '2'
SET("col_name", 0, "boolean");           //  col_name = false

DATA GROUPS (WHERE)

WHERE("AND|OR|ALL",
  SET(column, value, operator),
  SET(column, value, type, operator),
  WHERE(...)
);

WHERE("AND",
  SET("col_name", 1, ">=");              //  col_name >= 1
  SET("col_name", "text", "=");          //  && col_name == 'text'
  SET("col_name", "text", "==");         //  && col_name == 'text'
  SET("col_name", 2, "string", "=");     //  && col_name == '2'
  SET("col_name", 0, "boolean", "!=");   //  && col_name != false
);

WHERE("OR", 
  SET("col_name", "cheese", "="),        //  col_name == 'cheese'
  WHERE("AND",                           //  || (
    SET("col_name", 0, ">"),             //       col_name > 0
    SET("col_name", 10, "<")             //       && col_name < 10
  ),                                     //     )
  SET("col_name", false, "!=")           //  || col_name != false
);

INSERT DATA

INSERT(
  SET(...),                              //  Add as many sets as you need.
  ...
);

INSERT(
  SET("col1", "cheese"), 
  SET("col2", 2), 
  SET("col3", 0, "boolean")
);

SELECT DATA

SELECT(
  COLS(column, column, ...),             //  Add the columns you need returned. Note: these are strings, not sets.
  WHERE(...), 
  ORDER(column, sort),                   //  Optional; sort: blank/false for ascending, true for descending
  LIMIT(num)                             //  Optional
);
                                         //  d
$select = SELECT(
  COLS("id", "col1", "col2", "col3"),
  WHERE("OR", 
    SET("col1", "cheese", "="), 
    WHERE("AND", 
      SET("col2", 0, ">"),
      SET("col2", 10, "<")
    ),
    SET("col3", false, "!=")
  ), 
  ORDER("id", true),
  LIMIT(1)
);


/* SQL EQUIVALENT */
SELECT id, col1, col2, col3 
  FROM test_table 
  WHERE (col1 = 'cheese' OR (col2 > 0 AND col2 < 10) OR col3 != false) 
  ORDER BY id DESC 
  LIMIT 1;

UPDATE DATA

UPDATE(
  SELECT(...),                           //  This can also be the result of a previous SELECT function.
  SET(...),                              //  Add as many sets as you need.
  ...
);

UPDATE(
  $select,                               //  See "$select" in the SELECT example above.
  SET("val1", "sup"), 
  SET("val2", 3), 
  SET("val3", 3)
);

DELETE DATA

DELETE(id);                              //  You can only delete one record at a time.

DELETE(0);
DELETE(2);
DELETE(100);

EXAMPLE PHP FILE

require_once("database.php");

TABLE("test");

INSERT(
  SET("val1", "hello"), 
  SET("val2", 10), 
  SET("val3", 2)
);

INSERT(
  SET("val1", "world"), 
  SET("val2", 3), 
  SET("val3", 4)
);

$search1 = SELECT(
  COLS("id", 'val1', 'val2', 'val3'),
  WHERE("OR", 
    SET("val1", "hello", "="), 
    WHERE("AND", 
      SET("val2", 0, ">"), 
      SET("val3", 10, "<")
    )
  ), 
  ORDER("id", true)
);

echo json_encode($search1);

UPDATE(
  $search1,
  SET("val1", "hi"),
  SET("val3", 0)
);

$search2 = SELECT(
  COLS("id"),
  WHERE("ALL"), 
  ORDER("id", true),
  LIMIT(1)
);

DELETE($search2[0]['id']);