Contain
This is now development mode
- Select Data
- Relational Select Data
- Insert Data
- Update Data
- Delete Data
- Condition Parameter
- Condition syntax
- Insert Data
- Insert Data
Insert
Insert parameter | Description |
---|
table | table name . Example: db_name.table_name |
insert_data | Must be an object |
hasDate | (optional) If the table contains date name column. Default false |
date_field | (optional) Date column name. The date will be converted to UTC time zone |
import mysqlcrudsyntax from 'mysql-crud-syntax'
const insert = mysqlcrudsyntax.insertSyntax({
table: 'test',
insert_data: { name: 'X', age: 'test' },
date_field: 'entry_date',
hasDate: true
})
console.log(insert)
without date:
import mysqlcrudsyntax from 'mysql-crud-syntax'
const insert =mysqlcrudsyntax.insertSyntax({
table: 'test',
insert_data: { name: 'X', age: 'test', entry_date: new Date()},
})
console.log(insert)
Update
update parameter | Description |
---|
table | table name . Example: db_name.table_name |
data | Must be a condition object |
note: Should always call the getSyntax function at the end
import mysqlcrudsyntax from 'mysql-crud-syntax'
const update = {
name: "X",
age:100,
}
const up = mysqlcrudsyntax.updateSyntax({
data: update,
table: 'test'
}).and({
field_value: { name: 'test', done: true },
separate: ['!=']
}).between({
column_name: 'test',
from: 10,
to: 3
}).getSyntax()
DELETE
delete parameter | Description |
---|
table | table name . Example: db_name.table_name |
note: Should always call the getSyntax function at the end
import mysqlcrudsyntax from 'mysql-crud-syntax'
const dl = mysqlcrudsyntax.deleteSyntax({
table: 'test'
}).and({
field_value: { name: 'test', done: true },
separate: ['!=']
}).between({
column_name: 'test',
from: 10,
to: 3
}).getSyntax()
Condition
- AND Operation:
.and({
field_value: { name: 'rakib', age: 465 },
separate: ['!=', '=']
})
-- name != 'rakib' and age = 465
more.
.and({
field_value: { name: 'rakib', age: 465, test:5453 },
separate: ['=']
})
-- name = 'rakib' and age = 465 and test = 5453
parameter | Description |
---|
field_value | Field and value pairs will be contained within an object |
separate | '=', '>', '<', '>=', '<=', '!=' . Separates each value and key (object) . field value length may not be equal to an array. if they are not equal then defaults = |
- OR Operation:
same as AND Operation
.or({
field_value: { name: 'rakib', age: 465 },
separate: ['!=', '=']
})
-- name != 'rakib' or age = 465
more.
.or( {
field_value: { name: 'rakib', age: 465, test:5453 },
separate: ['=']
})
-- name = 'rakib' or age = 465 or test = 5453
- BETWEEN
In MySQL, the BETWEEN operator is used to match a value against a range of values.
The BETWEEN operator checks if the column_name value is between value1 and value2, and if it is, the row is returned by the query. The BETWEEN operator is inclusive, which means that if the column_name value is equal to either value1 or value2, it will still be included in the query result.
.between({
column_name: "column_name",
from: 'value1',
to: 'value2'
})
-- column_name BETWEEN value1 AND value2
SELECT *
FROM orders
WHERE order_date BETWEEN '2023-01-01' AND '2023-03-31';
- IN :
In MySQL, the IN operator is used to check if a value matches any value in a list of specified values.
The IN operator checks if the column_name value matches any of the specified values in the list (value1, value2, value3, ...). If there is a match, the row is returned by the query.
.include( {
column_name: 'column_name',
include_value: ['value1', 'value2', 'value3', 'value3',...s]
})
-- column_name IN (value1, value2, value3, ...);
SELECT *
FROM customers
WHERE country IN ('USA', 'Canada', 'Mexico');
- Pattern :
In MySQL, the LIKE operator is used to search for a pattern in a column.
.pattern( {
column_name: 'contact_name',
pattern_value: 'son'
patter_type: '%$% any value match',
equal: 'yes'
})
-- contact_name LIKE '%son%'
SELECT *
FROM customers
WHERE contact_name LIKE '%son%';
More.
.pattern({
column_name: 'contact_name',
pattern_value: 'son'
patter_type: '%$% any value match',
equal: 'no'
})
-- contact_name NOT LIKE '%son%'
Condition Syntax
condition syntax | Description |
---|
= | Equal to |
> | Greater than |
< | Less than |
>= | Greater than or equal to |
<= | Less than or equal to |
!= | Not equal to |
%$ end value match | Matches a pattern .Finds any values that end with |
$% start value match | Matches a pattern .Finds any values that start with |
%$% any value match | Matches a pattern .Finds any values that have in any position |