1.1.49 • Published 2 months ago

cordova-sqlite-react v1.1.49

Weekly downloads
-
License
ISC
Repository
github
Last release
2 months ago

The library is under development and is updated and corrected as needed!

    import { SLStore, Sqlite } from 'cordova-sqlite-react';
return Promise: Example
    
    Sqlite.openDB()
    Sqlite.closeDB()

    Sqlite.checkTable()//All tables.  { status: true, msg: 'Список найденных таблиц', tables }
    Sqlite.checkTable(nameTable)//checks a specific table.  promise -> { msg: "Таблица Test существует", status: true }
    Sqlite.setData(nameTable, payload, options)
    /* 
      Example payload:
        {name: 'Jon', age: 30, value: [{a: 1},{a: 2}] }
      
      options
      {
        isCreateDate: false //no create column createdAt and updateAt. default: true
        rewriteTable: true; //added request `DROP TABLE IF EXISTS ${nameTable}`
      }
    */  

    Sqlite.updateData(nameTable, payload, { where, stringWhere, condition })

    /*

    Example payload: ()
     
      Sqlite.updateData('test', {value: [{a: 4},{a: 2}]}, {where: {name: 'Jon'}})
      OR
      Sqlite.updateData('test', {value: [{a: 4},{a: 2}]}, {stringWhere: "WHERE name='Jon'"})

      {
        where: {name: 'Jon', age: 30} // generate WHERE name="Jon" AND age="30"
        condition: "AND" | "OR" //edit WHERE name="Jon" OR age="30"

        stringWhere: "WHERE name='Jon'" // manual setup WHERE
      }
    */


    Sqlite.getData(nameTable, { where, whereKey, ignoreWhere, stringWhere, condition }, isParse)

    Sqlite.removeData(nameTable, { where, whereKey, ignoreWhere, stringWhere, condition })

    /*
      {
        whereKey: {name: ['Jon', "Brain"], age: [25, 30]}}
      }
      'DELETE FROM ${nameTable} WHERE name = "Jon" OR name = "Brain", age = "17" OR age = "20"'
    */

    Sqlite.query(sql)//any sql query
  
 
    Sqlite.removeData('Test', {where: {key: 'Jon', age: 20}})
    //DELETE FROM Test WHERE key="Jon" OR age="20"

    Sqlite.removeData('Test', {whereKey: {key: ['Jon', 'Brain']} })
    //DELETE FROM Test WHERE key = "Jon" OR key = "Brain"
    Sqlite.removeData('Test', {whereKey: {key: ['Jon', 'Brain']}, ignoreWhere: {key: ['Jon', 'Alex']}, condition: 'AND'})
    //DELETE FROM Test WHERE key != "Jon" AND key = "Brain" AND key != "Alex"

    Sqlite.removeData('Test', {ignoreWhere: {key: ['Jon']} })
    //DELETE FROM Test WHERE key != "Jon"

    Sqlite.removeData('Test')
    //DELETE FROM Test    

    Sqlite.removeData('Test', {stringWhere: "WHERE name = 'Jon' OR name = 'Brain'"})
    //DELETE FROM Test WHERE name = 'Jon' OR name = 'Brain'

    /*---------------------------------------------------------------------------*/

    Sqlite.getData('Test') //SELECT * FROM Test
    /* 
      promise -> {
        msg: "Данные найдены",
        status: true,
        values: [
          {
            id: 1,
            key: "listNames",
            createdAt: "2023-02-07 14:03:23",
            updateAt: "2023-02-13 09:59:03",
            value: "[{\"name\":\"Jon\"}, {\"name\":\"Brain\"}]"
          },
           {
            id: 2,
            key: "listCity",
            createdAt: "2023-02-07 14:03:23",
            updateAt: "2023-02-13 09:59:03",
            value: "[{\"city\":\"New York\"}, {\"city\":\"California\"}]"
          },
          ...
        ]
      } 
    */

    Sqlite.getData('Test', {where: {key: 'listNames'}}, true) //SELECT * FROM Test WHERE key = 'listNames'
    /* 
      promise -> {
        msg: "Данные найдены",
        status: true,
        values: [
          {
            id: 1,
            key: "listNames",
            createdAt: "2023-02-07 14:03:23",
            updateAt: "2023-02-13 09:59:03",
            value: [ {name: "Jon"}, {name: "Brain"} ] <-- isParse
          }
        ]
      } 
    */
    
 

    Sqlite.dropTable(nameTable)

SLStore

The class aims to save data if cordova in sqlite, if web in localStorage. Most of it repeats the functionality of localStorage.

The table contains the "key" and "value" columns

  SLStore.setItem(key, value, options)// options from Sqlite.setData
  SLStore.getItem(key)//->{ msg:string, status:boolean, data: {[key]: any} }


  SLStore.getItems()//->{ data: {profile: {name: 'Jon', id: 1}, isDarkTheme: true}, msg: "Данные найдены", status: true }

  SLStore.getItems({ignoreKeys: ['profile']})//-> { data: {isDarkTheme: true}, msg: "Данные найдены", status: true }
  
  SLStore.removeItem({ignoreKey: ['Jon']})//remove all !== 'Jon'
  SLStore.removeItem({keys: ['Brain']})//remove all === 'Brain'
  SLStore.dropAllData()
  //for cordova: DROP TABLE IF EXISTS REACT_APP_SQLITE_TABLE_SETTINGS, for web localStorage.clear();
1.1.49

2 months ago

1.1.48

3 months ago

1.1.45

1 year ago

1.1.47

1 year ago

1.1.39

1 year ago

1.1.41

1 year ago

1.1.40

1 year ago

1.1.44

1 year ago

1.1.43

1 year ago

1.1.42

1 year ago

1.1.38

2 years ago

1.1.30

2 years ago

1.1.34

2 years ago

1.1.33

2 years ago

1.1.32

2 years ago

1.1.31

2 years ago

1.1.37

2 years ago

1.1.36

2 years ago

1.1.35

2 years ago

1.1.29

2 years ago

1.1.28

2 years ago

1.1.27

2 years ago

1.1.26

2 years ago

1.1.9

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.1.12

2 years ago

1.1.11

2 years ago

1.1.10

2 years ago

1.1.16

2 years ago

1.1.15

2 years ago

1.1.14

2 years ago

1.1.13

2 years ago

1.1.19

2 years ago

1.1.18

2 years ago

1.1.17

2 years ago

1.1.23

2 years ago

1.1.22

2 years ago

1.1.21

2 years ago

1.1.20

2 years ago

1.1.25

2 years ago

1.1.24

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago