Socket
Socket
Sign inDemoInstall

mysql-crud-syntax

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    mysql-crud-syntax

This is now development mode


Version published
Maintainers
1
Created

Readme

Source

Contain

This is now development mode

  1. Select Data
  2. Relational Select Data
  3. Insert Data
  4. Update Data
  5. Delete Data
  6. Condition Parameter
  7. Condition syntax
  8. Insert Data
  9. Insert Data

Insert

Insert parameterDescription
tabletable name . Example: db_name.table_name
insert_dataMust 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)

// INSERT INTO test (name,age,entry_date) VALUES ("X","test",UTC_TIMESTAMP())

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)
// INSERT INTO test (name,age,entry_date) VALUES ("X","test","2023-04-26T18:42:00.788Z")

Update

update parameterDescription
tabletable name . Example: db_name.table_name
dataMust 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 parameterDescription
tabletable 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

  1. 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
parameterDescription
field_valueField 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 =
  1. 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
  1. 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';
  1. 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');

  1. 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 syntaxDescription
=Equal to
>Greater than
<Less than
>=Greater than or equal to
<=Less than or equal to
!=Not equal to
%$ end value matchMatches a pattern .Finds any values that end with
$% start value matchMatches a pattern .Finds any values that start with
%$% any value matchMatches a pattern .Finds any values that have in any position

Keywords

FAQs

Last updated on 13 May 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc