colshrapnel / safemysql

A real safe and convenient way to handle MySQL queries.
Apache License 2.0
395 stars 197 forks source link

Could you please update composer package? #49

Closed AndriiHranat closed 6 years ago

AndriiHranat commented 6 years ago

Hello, thanks for this class! Your last change private field to protected was very useful for an extension. But if dev used composer them can't take this changes. So could you please update composer package?

colshrapnel commented 6 years ago

that's a very good idea but I seems unable to do so. Still trying but could use some help.

lcherone commented 6 years ago

You should remove "version": "1.0.0" from the composer.json and instead just use semvar tags as your doing, packagist will pick them up automatically.

To setup this repo with packagist:

Then when you tag a version of this lib, packagist will update.. else you need to goto packagist each time and click the big green update button. You still need to use tags though.

See my SO answer if you need pictures ;p https://stackoverflow.com/questions/48316610/composer-require-without-dev-master/48317157#48317157

Maybe it helps.

colshrapnel commented 6 years ago

@lcherone thank you a lot for this guide!

Actually mopvhs is not my account and I have no idea who it is. So I reclaimed the ownership and now I can update the package. By the way it was just amazing experience talking to Packagist support!

So now it works, I can update the package. I removed the explicit version as you said, but when I am doing composer require colshrapnel/safemysql, it still takes the old version, creating composer.json

{
    "require": {
        "colshrapnel/safemysql": "^1.0"
    }
}

only if I change ^1.0 to dev-master it gets me the latest version.

Should I put something like "version": "dev-master" to composer.json file in the package?

lcherone commented 6 years ago

The best way is to not have any version defined in this projects composer.json

Allow the consumers to use "minimum-stability": "dev" if they want the master branch, not a release tag e.g the semvar.

Each time you add a tag, it will update on packagist. ^1.0 is anything after 1.0 but not dev/master. So if you did:

// tag it
git tag -a v1.0.0 -m "Comment for version 1.0.0"

// push it
git push origin v1.0.0

User downloads 1.0.0, complains somethings broke on an issue ;p..

Do your changes/fixes, push them as normal, then tag your release..

// tag it
git tag -a v1.0.1 -m "Comment for version 1.0.1"

// push it
git push origin v1.0.1

Then to update, the user would do composer update, and it would pull down v1.0.1 (though there might be a delay of a few mins whilst its propagated on packagists cache)

Look into using semvar, e.g 0.0.0(major, minor, patch) not 0.0 (major, minor).. then you can do patch release before minor releases.. majors are new versions which may have breaking changes.. It makes life somewhat easier.

Hope it helps.

lcherone commented 6 years ago

For you, as the developer, you would have a composer.json:

{
    "minimum-stability": "dev",
    "require": {
        "colshrapnel/safemysql": "master"
    }
}

then work out of ./vendor/colshrapnel/ back at ./ would be your tester script where you would test the methods.. or you could add unit tests ;p:

<?php
require 'vendor/autoload.php';

$db = new SafeMySQL(array(
    'user'    => 'user',
    'pass'    => 'pass',
    'db'      => 'db',
    'charset' => 'latin1'
));

$name = $db->getOne('SELECT name FROM table WHERE id = ?i',$_GET['id']);
$data = $db->getInd('id','SELECT * FROM ?n WHERE id IN ?a','table', array(1,2));
$data = $db->getAll("SELECT * FROM ?n WHERE mod=?s LIMIT ?i",$table,$mod,$limit);

$ids  = $db->getCol("SELECT id FROM tags WHERE tagname = ?s",$tag);
$data = $db->getAll("SELECT * FROM table WHERE category IN (?a)",$ids);

$data = array('offers_in' => $in, 'offers_out' => $out);
$sql  = "INSERT INTO stats SET pid=?i,dt=CURDATE(),?u ON DUPLICATE KEY UPDATE ?u";
$db->query($sql,$pid,$data,$data);

if ($var === NULL) {
    $sqlpart = "field is NULL";
} else {
   $sqlpart = $db->parse("field = ?s", $var);
}
$data = $db->getAll("SELECT * FROM table WHERE ?p", $bar, $sqlpart);
colshrapnel commented 6 years ago

Finally I made it!

composer require colshrapnel/safemysql now installs the latest version

Thank you @whisperstars for opening the issue and @lcherone for your enormous help!