@@ -20,7 +20,7 @@ A Laravel package that allows you to easily load data into Oracle database using
2020You can install the package via composer:
2121
2222``` bash
23- composer require yajra/laravel-sql-loader
23+ composer require yajra/laravel-sql-loader:^1.0
2424```
2525
2626## Usage
@@ -86,6 +86,165 @@ Route::get('sql-loader', function () {
8686});
8787```
8888
89+ ## Execution Mode
90+
91+ The default execution mode is ` Mode::APPEND ` . The package supports the following execution mode:
92+
93+ - ` Yajra\SQLLoader\Mode::INSERT ` - Insert data into table.
94+ - ` Yajra\SQLLoader\Mode::APPEND ` - Append data to table.
95+ - ` Yajra\SQLLoader\Mode::REPLACE ` - Replace data in table.
96+ - ` Yajra\SQLLoader\Mode::TRUNCATE ` - Truncate table then insert data.
97+
98+ ## Available Methods
99+
100+ ### Options
101+
102+ You can pass additional options to the ` sqlldr ` command using the ` options ` method.
103+
104+ ``` php
105+ $loader->options(['skip=1', 'load=1000']);
106+ ```
107+
108+ ### Input File(/s)
109+
110+ You can set the input file to use for the SQL Loader command using the ` inFile ` method.
111+
112+ ``` php
113+ $loader->inFile(database_path('files/employees.csv'));
114+ ```
115+
116+ You can also set multiple input files.
117+
118+ ``` php
119+ $loader->inFile(database_path('files/employees.csv'))
120+ ->inFile(database_path('files/departments.csv')),
121+ ```
122+
123+ ### Mode
124+
125+ You can set the execution mode using the ` mode ` method.
126+
127+ ``` php
128+ $loader->mode(Yajra\SQLLoader\Mode::TRUNCATE);
129+ ```
130+
131+ ### Into Table
132+
133+ You can set the table to load the data into using the ` into ` method. This method accepts the following parameters:
134+
135+ - ` table ` - The table name.
136+ - ` columns ` - The columns to load.
137+ - ` terminatedBy ` - The terminated by character.
138+ - ` enclosedBy ` - The enclosed by character.
139+ - ` trailing ` - Set to true if the data is trailing.
140+ - ` formatOptions ` - The format options in array.
141+
142+ ``` php
143+ $loader->into('employees', ['name', 'dept_id']);
144+ ```
145+
146+ ### Disk
147+
148+ You can set the disk to use for the control file using the ` disk ` method.
149+
150+ ``` php
151+ $loader->disk('local');
152+ ```
153+
154+ ### Logging
155+
156+ You can get the logs of the execution using the ` logs ` method.
157+
158+ ``` php
159+ return nl2br($loader->logs());
160+ ```
161+
162+ ### Custom Control File
163+
164+ You can use a custom control file by passing the control file name to the ` as ` method.
165+
166+ ``` php
167+ $loader->as('employees.ctl');
168+ ```
169+
170+ ### Execute
171+
172+ You can execute the SQL Loader command using the ` execute ` method.
173+
174+ ``` php
175+ $loader->execute();
176+ ```
177+
178+ ### Execution Result
179+
180+ You can check if the execution was successful using the ` successfull ` method.
181+
182+ ``` php
183+ if ($loader->successfull()) {
184+ return 'Data loaded successfully!';
185+ }
186+ ```
187+
188+ ### Process Result
189+
190+ You can get the process result using the ` result ` method.
191+
192+ ``` php
193+ $result = $loader->result();
194+ ```
195+
196+ ## Using array as data source
197+
198+ You can use an array as a data source by using ` begindData ` method.
199+
200+ ``` php
201+ $loader = Yajra\SQLLoader\SQLLoader::make();
202+ $loader->beginData([
203+ ['John', 1],
204+ ['Jane', 1],
205+ ['Jim, K', 2],
206+ ['Joe', 2],
207+ ])
208+ ->mode(Yajra\SQLLoader\Mode::TRUNCATE)
209+ ->into('employees', [
210+ 'name',
211+ 'dept_id',
212+ ])
213+ ->execute();
214+ ```
215+
216+ ## Available Configuration
217+
218+ You can publish the configuration file using the following command:
219+
220+ ``` bash
221+ php artisan vendor:publish --provider=" Yajra\SQLLoader\SQLLoaderServiceProvider" --tag=" config"
222+ ```
223+
224+ ### Connection Config
225+
226+ You can set the connection name to use for the SQL Loader command.
227+
228+ ``` php
229+ 'connection' => env('SQL_LOADER_CONNECTION', 'oracle'),
230+ ```
231+
232+ ### SQL Loader Path Config
233+
234+ You can set the path to the SQL Loader executable.
235+
236+ ``` php
237+ 'sqlldr' => env('SQL_LOADER_PATH', '/usr/local/bin/sqlldr'),
238+ ```
239+
240+ ### Disk Config
241+
242+ You can set the disk to use for the control file.
243+
244+ ``` php
245+ 'disk' => env('SQL_LOADER_DISK', 'local'),
246+ ```
247+
89248## Credits
90249
91250- [ Arjay Angeles] [ link-author ]
0 commit comments