|
5 | 5 | [](https://github.com/furkifor/sql_dumper/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amaster) |
6 | 6 | [](https://packagist.org/packages/furkifor/sql_dumper) |
7 | 7 |
|
| 8 | +SQL query builder and database migration tool. |
| 9 | + |
| 10 | +## Installation |
| 11 | + |
8 | 12 | ```bash |
9 | 13 | composer require furkifor/sql_dumper |
10 | 14 | ``` |
11 | 15 |
|
12 | | -## Kullanımı |
| 16 | +## SQL Query Builder Usage |
13 | 17 |
|
14 | 18 | ```php |
15 | | -$sql_dumper = new Furkifor\SqlDumper("TABLE_NAME"); |
| 19 | +$sql_dumper = new Furkifor\SqlDumper("users"); |
| 20 | + |
| 21 | +// Simple query |
16 | 22 | echo $sql_dumper->select('*')->get(); |
17 | | -// select * from TABLE_NAME |
| 23 | +// SELECT * FROM users |
| 24 | + |
| 25 | +// Query with conditions |
| 26 | +echo $sql_dumper->select('name, email') |
| 27 | + ->where('age > ?', [18]) |
| 28 | + ->orderBy('name', 'DESC') |
| 29 | + ->limit(10) |
| 30 | + ->get(); |
| 31 | +// SELECT name, email FROM users WHERE age > ? ORDER BY name DESC LIMIT 10 |
| 32 | + |
| 33 | +// JOIN operations |
| 34 | +echo $sql_dumper->select('users.*, roles.name as role_name') |
| 35 | + ->join('INNER', 'roles', 'users.role_id = roles.id') |
| 36 | + ->where('users.active = ?', [1]) |
| 37 | + ->get(); |
| 38 | +// SELECT users.*, roles.name as role_name FROM users |
| 39 | +// INNER JOIN roles ON users.role_id = roles.id WHERE users.active = ? |
| 40 | + |
| 41 | +// Grouping and HAVING |
| 42 | +echo $sql_dumper->select('country, COUNT(*) as user_count') |
| 43 | + ->groupBy('country') |
| 44 | + ->having('user_count > 100') |
| 45 | + ->get(); |
| 46 | +// SELECT country, COUNT(*) as user_count FROM users |
| 47 | +// GROUP BY country HAVING user_count > 100 |
18 | 48 | ``` |
19 | | -## Migrate Kullanımı |
| 49 | + |
| 50 | +## Migration Tool Usage |
20 | 51 |
|
21 | 52 | ```php |
22 | 53 | $table = new MigrateClass("mysql"); |
| 54 | + |
| 55 | +// Simple table creation |
23 | 56 | $table->name("users") |
24 | | - ->string('username',255)->unique()->notnull() |
25 | | - ->string('email',255)->unique()->notnull() |
26 | | - ->string('password',255)->notnull() |
| 57 | + ->string('username', 255)->unique()->notnull() |
| 58 | + ->string('email', 255)->unique()->notnull() |
| 59 | + ->string('password', 255)->notnull() |
27 | 60 | ->datetime('created_at')->default("CURRENT_TIMESTAMP") |
28 | | - ->int('role_id')->notnull()->foreignKey('roles','id')->check("role_id>0") |
29 | 61 | ->createTable(); |
30 | | -/* |
31 | | -CREATE TABLE users ( |
32 | | - id INT(11) AUTO_INCREMENT PRIMARY KEY NOT NULL, |
33 | | - username VARCHAR(255) NOT NULL UNIQUE, |
34 | | - email VARCHAR(255) NOT NULL UNIQUE, |
35 | | - password VARCHAR(255) NOT NULL, |
36 | | - created_at DATETIME DEFAULT CURRENT_TIMESTAMP, |
37 | | - role_id INT NOT NULL, |
38 | | - FOREIGN KEY (role_id) REFERENCES roles(id), |
39 | | - CHECK (role_id > 0) |
40 | | -) |
41 | | -*/ |
| 62 | + |
| 63 | +// Table with relationships |
| 64 | +$table->name("posts") |
| 65 | + ->string('title', 255)->notnull() |
| 66 | + ->text('content') |
| 67 | + ->int('user_id')->notnull() |
| 68 | + ->foreignKey('user_id', 'users', 'id') |
| 69 | + ->datetime('published_at')->nullable() |
| 70 | + ->boolean('is_published')->default(0) |
| 71 | + ->createTable(); |
| 72 | + |
| 73 | +// Table with custom constraints |
| 74 | +$table->name("products") |
| 75 | + ->string('name', 100)->notnull() |
| 76 | + ->decimal('price', 10, 2)->notnull() |
| 77 | + ->int('stock')->notnull()->default(0) |
| 78 | + ->check('price > 0') |
| 79 | + ->check('stock >= 0') |
| 80 | + ->createTable(); |
42 | 81 | ``` |
43 | 82 |
|
| 83 | +## Features |
44 | 84 |
|
45 | | -- [furkan](https://github.com/FurkiFor) |
46 | | -- [All Contributors](../../contributors) |
| 85 | +### SQL Query Builder |
| 86 | +- CREATE SELECT queries |
| 87 | +- WHERE conditions |
| 88 | +- JOIN operations (INNER, LEFT, RIGHT) |
| 89 | +- ORDER BY sorting |
| 90 | +- GROUP BY grouping |
| 91 | +- HAVING filtering |
| 92 | +- LIMIT clause |
| 93 | +- Parameter binding support |
| 94 | +- DISTINCT queries |
| 95 | + |
| 96 | +### Migration Tool |
| 97 | +- Multiple database system support (MySQL, MongoDB, SQL Server) |
| 98 | +- Support for all common data types |
| 99 | +- Automatic ID/Primary Key generation |
| 100 | +- Foreign Key relationships |
| 101 | +- Unique constraints |
| 102 | +- NOT NULL constraints |
| 103 | +- DEFAULT values |
| 104 | +- CHECK constraints |
| 105 | + |
| 106 | +## Contributing |
| 107 | + |
| 108 | +Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. |
47 | 109 |
|
48 | 110 | ## License |
49 | 111 |
|
50 | 112 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. |
| 113 | + |
| 114 | +## Credits |
| 115 | + |
| 116 | +- [Furkan Ünsal](https://github.com/FurkiFor) |
| 117 | +- [All Contributors](../../contributors) |
0 commit comments