@@ -47,7 +47,7 @@ The plugin add a suffix "SQLite" and an extension ".db" to the database name giv
4747
4848 - for sharing databases between users:
4949
50- ```
50+ ``` ts
5151 plugins : {
5252 CapacitorSQLite : {
5353 electronMacLocation : " /YOUR_DATABASES_PATH" ,
@@ -95,6 +95,66 @@ The plugin add a suffix "SQLite" and an extension ".db" to the database name giv
9595
9696 - see [Comments within SQL](https://www.techonthenet.com/sqlite/comments.php)
9797
98+ - Some examples
99+
100+ ```ts
101+ const setContacts: Array<capSQLiteSet> = [
102+ { statement:"INSERT INTO contacts /* Contact Simpson */ (name ,FirstName ,email ,company ,age ,MobileNumber ) VALUES (? ,? ,? ,? ,? ,? );" ,
103+ values : [" Simpson" ," Tom" ," Simpson@example.com" ,,69 ," 4405060708" ]
104+ },
105+ { statement:" INSERT INTO contacts /* three more contacts */ (name,FirstName,email,company,age,MobileNumber) VALUES (?,?,?,?,?,?) -- Add Jones, Whiteley and Brown;" ,
106+ values:[
107+ [" Jones" ," David" ," Jones@example.com" ,,42.1 ," 4404030201" ],
108+ [" Whiteley" ," Dave" ," Whiteley@example.com" ,,45.3 ," 4405162732" ],
109+ [" Brown" ," John" ," Brown@example.com" ,,35 ," 4405243853" ]
110+ ]
111+ },
112+ { statement:" UPDATE contacts SET age = ? , MobileNumber = ? WHERE id = ? -- Update Jones Contact;" ,
113+ values:[51.4 ," 4404030202" ,6 ]
114+ }
115+ ];
116+ const setMessages : Array < capSQLiteSet > = [
117+ { statement:`
118+ /* Define the messages table */
119+ CREATE TABLE IF NOT EXISTS messages (
120+ id INTEGER PRIMARY KEY NOT NULL,
121+ contactid INTEGER, -- key to contacts(id)
122+ title TEXT NOT NULL,
123+ body TEXT NOT NULL,
124+ last_modified INTEGER DEFAULT (strftime('%s', 'now')),
125+ FOREIGN KEY (contactid) REFERENCES contacts(id) ON DELETE SET DEFAULT
126+ ); ` ,
127+ values:[]
128+ },
129+ ];
130+
131+ let insertQuery = ' INSERT INTO contacts (name,FirstName,email,company,age,MobileNumber) VALUES (?, ?, ?, ?, ?, ?) -- Add Sue Hellen;' ;
132+ let bindValues = [" Hellen" ," Sue" ," sue.hellen@example.com" ,,42 ," 4406050807" ];
133+ let ret = await db .run (insertQuery , bindValues );
134+ console .log (` >>> run ret 1: ${JSON .stringify (ret )} ` )
135+ insertQuery = ` INSERT INTO contacts /* some contacts */ (name,FirstName,email,company,age,MobileNumber) VALUES
136+ ('Doe','John','john.doe@example.com', 'IBM', 30, '4403050926'), -- add Doe
137+ ('Watson','Dave','dave.watson@example.com','Apple', 30, '4407050932') /* add Watson */,
138+ ('Smith', 'Jane', 'jane.smith@example.com', 'IBM', 27, '33607556142') /* Add Smith */-- End of add contact; ` ;
139+ bindValues = [];
140+ ret = await db .run (insertQuery , bindValues );
141+ console .log (` >>> run ret 2: ${JSON .stringify (ret )} ` )
142+
143+ let selectQuery = " SELECT * /* all columns */ FROM contacts WHERE company = 'IBM' -- for company IBM;" ;
144+
145+ ret = await db .query (selectQuery );
146+ console .log (` >>> query "IBM" ret: ${JSON .stringify (ret )} ` )
147+
148+ ret = await db .executeSet (setContacts );
149+ console .log (` >>> executeSet 1 ret: ${JSON .stringify (ret )} ` )
150+
151+ selectQuery = " SELECT email /* only email */ FROM contacts WHERE company ISNULL -- for company not given;" ;
152+
153+
154+ ret = await db .executeSet (setMessages );
155+ console .log (` >>> executeSet 2 ret: ${JSON .stringify (ret )} ` )
156+ ` ` `
157+
98158## Unexpected behaviours
99159
100160Unexpected or erroneous behaviour users of this library have encountered.
0 commit comments