1
1
    [](https://twitter.com/congocart)
2
2
3
3
# NativeScript sqlite
4
- <table ><tr ><td >
5
- <a href =" https://proplugins.org " ><img src =" https://proplugins.org/logos/logo.png " width =" 200 " /></a >
6
- </td ><td >
7
- <div >Sponsored By:<br >
8
- <a href =" https://master.technology " ><img src =" https://proplugins.org/logos/mt-banner.png " width =" 200 " /></a ></div >
9
- </td ></tr ></table >
10
-
11
4
12
5
A NativeScript module providing sqlite actions for Android and iOS. (with multi-threading)
13
6
@@ -45,7 +38,7 @@ This file is REQUIRED for normal un-encrypted sqlite; but it can conflict with e
45
38
46
39
## Example Application
47
40
48
- An example application can be downloaded form npm.proplugins.org or cloned from git.proplugins.org, in the demo folder.
41
+ An example application can be downloaded or cloned from https://github.com/NathanaelA/nativescript-sqlite
49
42
To use you need to do:
50
43
* ` npm i `
51
44
* ` tns run `
@@ -60,7 +53,7 @@ Then run the app the normal way you would.
60
53
61
54
## Installation
62
55
63
- Run ` tns plugin add @proplugins/ nativescript-sqlite ` in your ROOT directory of your project.
56
+ Run ` tns plugin add nativescript-sqlite ` in your ROOT directory of your project.
64
57
65
58
*** optional***
66
59
* ` tns plugin add ./plugins/nativescript-sqlite-commercial-???.tgz `
@@ -101,12 +94,12 @@ so that it ignores those during webpacking, right below the line that says
101
94
To use the sqlite module you must first ` require() ` it:
102
95
103
96
``` js
104
- const Sqlite = require ( " @proplugins/ nativescript-sqlite" );
97
+ const Sqlite = require ( " nativescript-sqlite" );
105
98
```
106
99
107
100
(or with TypeScript, if using the commercial version)
108
101
``` ts
109
- import { Sqlite } from " @proplugins/ nativescript-sqlite" ;
102
+ import Sqlite from " nativescript-sqlite" ;
110
103
```
111
104
112
105
After you have a reference to the module you can then call the available methods.
@@ -138,6 +131,7 @@ If you are planning on shipping a database with the application; drop the file i
138
131
139
132
### Methods
140
133
#### new Sqlite(dbname, options, callback)
134
+ #### promise = Sqlite(dbname, options, callback)
141
135
##### Parameters
142
136
* dbname: your database name. This can be ":memory:" for a memory Database. This can be "" for a Temporary Database.
143
137
* options
@@ -151,26 +145,29 @@ If you are planning on shipping a database with the application; drop the file i
151
145
You should choose either to use a promise or a callback; you can use whichever you are most comfortable with -- however, as with this example, you CAN use both if you want; but side effects WILL occur with some functions.
152
146
153
147
``` js
154
- // my-page.js
155
- const Sqlite = require ( " /path/to/node_modules/nativescript-sqlite" );
156
- const db_promise = new Sqlite (" MyTable" , function (err , db ) {
148
+ // Promise based example
149
+ const Sqlite = require ( " nativescript-sqlite" );
150
+
151
+ const db = await Sqlite (" MyTable" );
152
+ console .log (" Are we open yet (Promise based)? " , db .isOpen () ? " Yes" : " No" ); // Yes
153
+ ```
154
+
155
+ or
156
+
157
+ ``` js
158
+ // Callback based example
159
+ const Sqlite = require ( " nativescript-sqlite" );
160
+ new Sqlite (" MyTable" , function (err , db ) {
157
161
if (err) {
158
162
console .error (" We failed to open database" , err);
159
163
} else {
160
164
// This should ALWAYS be true, db object is open in the "Callback" if no errors occurred
161
- console .log (" Are we open yet (Inside Callback)? " , db .isOpen () ? " Yes" : " No" ); // Yes
165
+ console .log (" Are we open yet (Callback based )? " , db .isOpen () ? " Yes" : " No" ); // Yes
162
166
}
163
167
});
164
-
165
- db_promise .then (function (db ) {
166
- // This should ALWAYS be true, db object is open in the "then"
167
- console .log (" Are we open yet (Inside Promise)? " , db .isOpen () ? " Yes" : " No" ); // Yes
168
- db .close ();
169
- }, function (err ) {
170
- console .error (" We failed to open database" , err);
171
- });
172
168
```
173
169
170
+
174
171
#### Sqlite.isSqlite()
175
172
##### Parameters
176
173
* object to check
0 commit comments