@@ -10,7 +10,7 @@ or [DBI](https://metacpan.org/pod/DBI).
1010## How to Install :
1111From Source :
1212``` bash
13- git clone -b v0.
7 [email protected] :CellBIS/CellBIS-SQL-Abstract.git
13+ git clone -b v0.
8 [email protected] :CellBIS/CellBIS-SQL-Abstract.git
1414perl Makefile.PL
1515make && make test
1616make install && make clean
@@ -29,6 +29,9 @@ cpanm CellBIS::SQL::Abstract
2929use CellBIS::SQL::Abstract
3030my $sql_abstract = CellBIS::SQL::Abstract-> new;
3131
32+ # For create table SQLite
33+ my $sql_abstract = CellBIS::SQL::Abstract-> new(db_type => ' sqlite' );
34+
3235# Create Table
3336my $table_name = ' my_table_name' ; # Table name.
3437my $col_list = []; # List of column table
@@ -68,11 +71,14 @@ $sql_abstract->select_join($table_list, $column, $clause);
6871## Methods
6972
7073` CellBIS::SQL::Abstract ` inherit from [ Mojo::Base] ( https://metacpan.org/pod/Mojo::Base ) .
71- Methods ` insert ` , ` update ` , ` select ` , and ` select_join ` can use ** prepare statement** or ** not** .
74+ Methods ` insert ` , ` update ` , ` select ` , and ` select_join ` .
75+
76+ ` create_table ` is additional method.
77+ Currently, only supports MariaDB/MySQL and SQLite Syntax
7278
7379The following are the methods available from this module:
7480
75- ### create_table :
81+ ### create_table - MariaDB/MySQL :
7682``` perl
7783use CellBIS::SQL::Abstract
7884my $sql_abstract = CellBIS::SQL::Abstract-> new;
@@ -112,7 +118,7 @@ my $col_attr = {
112118};
113119my $create_table = $sql_abstract -> create_table($table_name , $col_list , $col_attr );
114120```
115- This equivalent with :
121+ SQL Equivalent :
116122``` mysql
117123CREATE TABLE IF NOT EXISTS users(
118124 id INT (11 ) NOT NULL PRIMARY KEY AUTO_INCREMENT,
@@ -122,7 +128,55 @@ CREATE TABLE IF NOT EXISTS users(
122128) ENGINE= InnoDB DEFAULT CHARSET= utf8
123129```
124130
125- ### create_table with Foreign key
131+ ### create_table - SQLite :
132+ ``` perl
133+ use CellBIS::SQL::Abstract
134+
135+ my $sql_abstract = CellBIS::SQL::Abstract-> new(db_type => ' sqlite' );
136+
137+ my $table_name = ' my_users' ;
138+ my $col_list = [ ' id' , ' first_name' , ' last_name' , ' other_col_name' ];
139+ my $col_attr = {
140+ ' id' => {
141+ type => { name => ' integer' },
142+ is_primarykey => 1,
143+ is_autoincre => 1,
144+ },
145+ ' first_name' => {
146+ type => {
147+ name => ' varchar' ,
148+ size => 50,
149+ },
150+ is_null => 0,
151+ },
152+ ' last_name' => {
153+ type => {
154+ name => ' varchar' ,
155+ size => 50,
156+ },
157+ is_null => 0,
158+ },
159+ ' other_col_name' => {
160+ type => {
161+ name => ' varchar' ,
162+ size => 60,
163+ },
164+ is_null => 0,
165+ }
166+ };
167+ $create_table = $sql_abstract -> create_table($table_name , $col_list , $col_attr );
168+ ```
169+ SQL Equivalent :
170+ ``` sqlite
171+ CREATE TABLE IF NOT EXISTS users(
172+ id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
173+ first_name VARCHAR NOT NULL,
174+ last_name VARCHAR NOT NULL,
175+ other_col_name VARCHAR(60) NOT NULL
176+ )
177+ ```
178+
179+ ### create_table with Foreign key - MariaDB/MySQL
126180``` perl
127181use CellBIS::SQL::Abstract
128182my $sql_abstract = CellBIS::SQL::Abstract-> new;
@@ -173,7 +227,7 @@ my $table_attr = {
173227};
174228my $create_table = $sql_abstract -> create_table($table_name , $col_list , $col_attr , $table_attr );
175229```
176- This equivalent with :
230+ SQL Equivalent :
177231``` mysql
178232CREATE TABLE IF NOT EXISTS company(
179233 id_company INT (11 ) NOT NULL PRIMARY KEY AUTO_INCREMENT,
@@ -185,6 +239,63 @@ CREATE TABLE IF NOT EXISTS company(
185239) ENGINE= InnoDB DEFAULT CHARSET= utf8;
186240```
187241
242+ ### create_table with Foreign key - SQLite
243+ ``` perl
244+ use CellBIS::SQL::Abstract
245+
246+ my $sql_abstract = CellBIS::SQL::Abstract-> new(db_type => ' sqlite' );
247+
248+ my $table_name = ' my_companies' ;
249+ my $col_list = [
250+ ' id_company' ,
251+ ' id_company_users' ,
252+ ' company_name' ,
253+ ];
254+ my $col_attr = {
255+ ' id_company' => {
256+ type => { name => ' integer' },
257+ is_primarykey => 1,
258+ is_autoincre => 1,
259+ },
260+ ' id_company_users' => {
261+ type => { name => ' integer' },
262+ is_null => 0,
263+ },
264+ ' company_name' => {
265+ type => {
266+ name => ' varchar' ,
267+ size => ' 200' ,
268+ },
269+ is_null => 0,
270+ }
271+ };
272+ my $table_attr = {
273+ fk => {
274+ name => ' user_companies_fk' ,
275+ col_name => ' id_company_users' ,
276+ table_target => ' users' ,
277+ col_target => ' id' ,
278+ attr => {
279+ onupdate => ' cascade' ,
280+ ondelete => ' cascade'
281+ }
282+ },
283+ charset => ' utf8' ,
284+ engine => ' innodb' ,
285+ };
286+ $create_table = $sql_abstract -> create_table($table_name , $col_list , $col_attr , $table_attr );
287+ ```
288+ SQL Equivalent :
289+ ``` sqlite
290+ CREATE TABLE IF NOT EXISTS company(
291+ id_company INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
292+ id_company_users INTEGER NOT NULL,
293+ company_name VARCHAR NOT NULL,
294+ CONSTRAINT user_company_fk FOREIGN KEY (id_company_users) REFERENCES users (id)
295+ ON DELETE CASCADE ON UPDATE CASCADE
296+ )
297+ ```
298+
188299### insert
189300``` perl
190301use CellBIS::SQL::Abstract
0 commit comments