Browse Source

Starting to implements SQL connectivity

PabloPuig1 2 years ago
parent
commit
30542fe488
6 changed files with 553 additions and 361 deletions
  1. 405
    308
      package-lock.json
  2. 3
    0
      package.json
  3. 1
    1
      screens/account.js
  4. 52
    3
      screens/solicitar.js
  5. 35
    0
      shared/routes.js
  6. 57
    49
      yarn.lock

+ 405
- 308
package-lock.json
File diff suppressed because it is too large
View File


+ 3
- 0
package.json View File

@@ -17,10 +17,13 @@
17 17
     "@react-navigation/drawer": "^6.5.1",
18 18
     "@react-navigation/native": "^6.0.14",
19 19
     "@react-navigation/native-stack": "^6.9.2",
20
+    "body-parser": "^1.20.1",
20 21
     "expo": "~47.0.7",
21 22
     "expo-dev-client": "~2.0.1",
22 23
     "expo-status-bar": "~1.4.2",
23 24
     "expo-web-browser": "^12.0.0",
25
+    "express": "^4.18.2",
26
+    "mysql": "^2.18.1",
24 27
     "react": "18.1.0",
25 28
     "react-dom": "18.1.0",
26 29
     "react-native": "0.70.5",

+ 1
- 1
screens/account.js View File

@@ -1,6 +1,6 @@
1 1
 import * as React from 'react';
2 2
 import {useState} from "react";
3
-import { StyleSheet, View, Text } from 'react-native';
3
+import { StyleSheet, View, Text} from 'react-native';
4 4
 import Header from '../shared/header';
5 5
 
6 6
 export default function Account({navigation}) {

+ 52
- 3
screens/solicitar.js View File

@@ -1,11 +1,60 @@
1 1
 import * as React from 'react';
2
-import { StyleSheet, View, Text } from 'react-native';
2
+import { StyleSheet, View, Text, Button, Linking } from 'react-native';
3 3
 import Header from '../shared/header';
4 4
 
5
+const express = require('express');
6
+const bodyParser = require('body-parser');
7
+const mysql = require('mysql');
8
+
9
+const connection = mysql.createPool({
10
+    host     : 'ada.uprrp.edu',
11
+    user     : 'pablo.puig1',
12
+    passw    : '9NA3kSExI2fGE6eV',
13
+    database : 'techos'
14
+});
15
+
16
+// Starting our app.
17
+const app = express();
18
+
19
+// Creating a GET route that returns data from the 'users' table.
20
+app.get('/users', function (req, res) {
21
+    // Connecting to the database.
22
+    connection.getConnection(function (err, connection) {
23
+
24
+    // Executing the MySQL query (select all data from the 'users' table).
25
+    connection.query('SELECT * FROM users', function (error, results, fields) {
26
+      // If some error occurs, we throw an error.
27
+      if (error) throw error;
28
+
29
+      // Getting the 'response' from the database and sending it to our route. This is were the data is.
30
+      res.send(results)
31
+    });
32
+  });
33
+});
34
+
35
+// Starting our server.
36
+app.listen(3000, () => {
37
+ console.log('Go to http://localhost:3000/users so you can see the data.');
38
+});
39
+
40
+
41
+
42
+
5 43
 export default function Solicitar({navigation}) {
6 44
     return (
7 45
         <View style={styles.container}>
8
-         <Text>Solicitar Screen</Text>
46
+         <Text>Solicitar Screen{"\n\n"}</Text>
47
+         <Button
48
+            onPress={ () => {Linking.openURL("https://forms.gle/SciwvAdF3TAE6hE97")}}
49
+            title="Solicita Ayuda"
50
+            accessibilityLable="Solicitar presionando el botón"
51
+         />
52
+         <Text>{"\n\n"}</Text>
53
+         try(){
54
+            fetch('http://ada.uprrp.edu:3000/users')
55
+            .then(response => response.json())
56
+            .then(users => console.warn(users))
57
+         }
9 58
         </View>
10 59
     )
11 60
 }
@@ -14,4 +63,4 @@ const styles = StyleSheet.create({
14 63
     container: {
15 64
         padding: 24
16 65
     },
17
-});
66
+});

+ 35
- 0
shared/routes.js View File

@@ -0,0 +1,35 @@
1
+var express = require('express');
2
+var app = express();
3
+
4
+var mysql = require('mysql');
5
+var bodyParser = require('body-parser');
6
+
7
+app.use(bodyParser.json({type:'application/json'}));
8
+app.use(bodyParser.urlencoded({extended:true}));
9
+
10
+var con = mysql.createConnectionI({
11
+    host:'ada.uprrp.edu',
12
+    user: 'pablo.puig1',
13
+    password: '9NA3kSExI2fGE6eV',
14
+    database: 'techos'
15
+
16
+});
17
+
18
+var server = app.listen(4545, function(){
19
+    var host = server.address().address
20
+    var host = server.address().port
21
+});
22
+
23
+con.connect(function(error){
24
+    if(error) console.log(error);
25
+    else console.log('connected');
26
+})
27
+
28
+app.get('/users', function(req, res){
29
+    con.query('SELECT * FROM users', function(error, rows, fields){
30
+        if(error) console.log(error)
31
+        else{
32
+            console.log(rows);
33
+        }
34
+    })
35
+})

+ 57
- 49
yarn.lock View File

@@ -2992,6 +2992,11 @@
2992 2992
   "resolved" "https://registry.npmjs.org/big.js/-/big.js-5.2.2.tgz"
2993 2993
   "version" "5.2.2"
2994 2994
 
2995
+"bignumber.js@9.0.0":
2996
+  "integrity" "sha512-t/OYhhJ2SD+YGBQcjY8GzzDHEk9f3nerxjtfa6tlMXfe7frs/WozhvCNoGvpM0P3bNf3Gq5ZRMlGr5f3r4/N8A=="
2997
+  "resolved" "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.0.0.tgz"
2998
+  "version" "9.0.0"
2999
+
2995 3000
 "binary-extensions@^1.0.0":
2996 3001
   "integrity" "sha512-Un7MIEDdUC5gNpcGDV97op1Ywk748MpHcFTHoYs6qnj1Z3j7I53VG3nwZhKzoBZmbdRNnb6WRdFlwl7tSDuZGw=="
2997 3002
   "resolved" "https://registry.npmjs.org/binary-extensions/-/binary-extensions-1.13.1.tgz"
@@ -3002,13 +3007,6 @@
3002 3007
   "resolved" "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz"
3003 3008
   "version" "2.2.0"
3004 3009
 
3005
-"bindings@^1.5.0":
3006
-  "integrity" "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ=="
3007
-  "resolved" "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz"
3008
-  "version" "1.5.0"
3009
-  dependencies:
3010
-    "file-uri-to-path" "1.0.0"
3011
-
3012 3010
 "bl@^4.1.0":
3013 3011
   "integrity" "sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w=="
3014 3012
   "resolved" "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz"
@@ -3048,23 +3046,7 @@
3048 3046
   "resolved" "https://registry.npmjs.org/bn.js/-/bn.js-5.2.1.tgz"
3049 3047
   "version" "5.2.1"
3050 3048
 
3051
-"body-parser@1.19.0":
3052
-  "integrity" "sha512-dhEPs72UPbDnAQJ9ZKMNTP6ptJaionhP5cBb541nXPlW60Jepo9RV/a4fX4XWW9CuFNK22krhrj1+rgzifNCsw=="
3053
-  "resolved" "https://registry.npmjs.org/body-parser/-/body-parser-1.19.0.tgz"
3054
-  "version" "1.19.0"
3055
-  dependencies:
3056
-    "bytes" "3.1.0"
3057
-    "content-type" "~1.0.4"
3058
-    "debug" "2.6.9"
3059
-    "depd" "~1.1.2"
3060
-    "http-errors" "1.7.2"
3061
-    "iconv-lite" "0.4.24"
3062
-    "on-finished" "~2.3.0"
3063
-    "qs" "6.7.0"
3064
-    "raw-body" "2.4.0"
3065
-    "type-is" "~1.6.17"
3066
-
3067
-"body-parser@1.20.1":
3049
+"body-parser@^1.20.1", "body-parser@1.20.1":
3068 3050
   "integrity" "sha512-jWi7abTbYwajOytWCQc37VulmWiRae5RyTpaCyDcS5/lMdtwSz5lOpDE67srw/HYe35f1z3fDQw+3txg7gNtWw=="
3069 3051
   "resolved" "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz"
3070 3052
   "version" "1.20.1"
@@ -3082,6 +3064,22 @@
3082 3064
     "type-is" "~1.6.18"
3083 3065
     "unpipe" "1.0.0"
3084 3066
 
3067
+"body-parser@1.19.0":
3068
+  "integrity" "sha512-dhEPs72UPbDnAQJ9ZKMNTP6ptJaionhP5cBb541nXPlW60Jepo9RV/a4fX4XWW9CuFNK22krhrj1+rgzifNCsw=="
3069
+  "resolved" "https://registry.npmjs.org/body-parser/-/body-parser-1.19.0.tgz"
3070
+  "version" "1.19.0"
3071
+  dependencies:
3072
+    "bytes" "3.1.0"
3073
+    "content-type" "~1.0.4"
3074
+    "debug" "2.6.9"
3075
+    "depd" "~1.1.2"
3076
+    "http-errors" "1.7.2"
3077
+    "iconv-lite" "0.4.24"
3078
+    "on-finished" "~2.3.0"
3079
+    "qs" "6.7.0"
3080
+    "raw-body" "2.4.0"
3081
+    "type-is" "~1.6.17"
3082
+
3085 3083
 "bonjour@^3.5.0":
3086 3084
   "integrity" "sha512-RaVTblr+OnEli0r/ud8InrU7D+G0y6aJhlxaLa6Pwty4+xoxboF1BsUI45tujvRpbj9dQVoglChqonGAsjEBYg=="
3087 3085
   "resolved" "https://registry.npmjs.org/bonjour/-/bonjour-3.5.0.tgz"
@@ -4332,9 +4330,9 @@
4332 4330
   "version" "1.2.0"
4333 4331
 
4334 4332
 "decode-uri-component@^0.2.0":
4335
-  "integrity" "sha512-hjf+xovcEn31w/EUYdTXQh/8smFL/dzYjohQGEIgjyNavaJfBY2p5F527Bo1VPATxv0VYTUC2bOcXvqFwk78Og=="
4336
-  "resolved" "https://registry.npmjs.org/decode-uri-component/-/decode-uri-component-0.2.0.tgz"
4337
-  "version" "0.2.0"
4333
+  "integrity" "sha512-FqUYQ+8o158GyGTrMFJms9qh3CqTKvAqgqsTnkLI8sKu0028orqBhxNMFkFen0zGyg6epACD32pjVk58ngIErQ=="
4334
+  "resolved" "https://registry.npmjs.org/decode-uri-component/-/decode-uri-component-0.2.2.tgz"
4335
+  "version" "0.2.2"
4338 4336
 
4339 4337
 "deep-equal@^1.0.1":
4340 4338
   "integrity" "sha512-yd9c5AdiqVcR+JjcwUQb9DkhJc8ngNr0MahEBGvDiJw8puWab2yZlh+nkasOnZP+EGTAP6rRp2JzJhJZzvNF8g=="
@@ -5057,9 +5055,9 @@
5057 5055
     "compare-urls" "^2.0.0"
5058 5056
 
5059 5057
 "expo@*", "expo@~47.0.7":
5060
-  "integrity" "sha512-uHTxvPdD4K7W277tXVAdFmgjSZ0Hg+0g5bnez0jXyXQINa+0CTtGmulgFehBOrbrUZBqwosN0K8TsrxADwcXZQ=="
5061
-  "resolved" "https://registry.npmjs.org/expo/-/expo-47.0.7.tgz"
5062
-  "version" "47.0.7"
5058
+  "integrity" "sha512-PGNCIvrnYwHH4TDFsVocq/xhWZ5DW8N3bLkZJPZZgX6VgjtVLNsbZ+0lm1inLCZHP+6xSpSKRccjGHO/QQoMBQ=="
5059
+  "resolved" "https://registry.npmjs.org/expo/-/expo-47.0.8.tgz"
5060
+  "version" "47.0.8"
5063 5061
   dependencies:
5064 5062
     "@babel/runtime" "^7.14.0"
5065 5063
     "@expo/cli" "0.4.10"
@@ -5086,7 +5084,7 @@
5086 5084
   optionalDependencies:
5087 5085
     "expo-error-recovery" "~4.0.1"
5088 5086
 
5089
-"express@^4.17.1":
5087
+"express@^4.17.1", "express@^4.18.2":
5090 5088
   "integrity" "sha512-5/PsL6iGPdfQ/lKM1UuielYgv3BUoJfz1aUwU9vHZ+J7gyvwdQXFEBIEIaxeGf0GIcreATNyBExtalisDbuMqQ=="
5091 5089
   "resolved" "https://registry.npmjs.org/express/-/express-4.18.2.tgz"
5092 5090
   "version" "4.18.2"
@@ -5556,19 +5554,6 @@
5556 5554
   "resolved" "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz"
5557 5555
   "version" "1.0.0"
5558 5556
 
5559
-"fsevents@^1.2.7":
5560
-  "integrity" "sha512-oWb1Z6mkHIskLzEJ/XWX0srkpkTQ7vaopMQkyaEIoq0fmtFVxOthb8cCxeT+p3ynTdkk/RZwbgG4brR5BeWECw=="
5561
-  "resolved" "https://registry.npmjs.org/fsevents/-/fsevents-1.2.13.tgz"
5562
-  "version" "1.2.13"
5563
-  dependencies:
5564
-    "bindings" "^1.5.0"
5565
-    "nan" "^2.12.1"
5566
-
5567
-"fsevents@^2.1.2", "fsevents@~2.3.2":
5568
-  "integrity" "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA=="
5569
-  "resolved" "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz"
5570
-  "version" "2.3.2"
5571
-
5572 5557
 "function-bind@^1.1.1":
5573 5558
   "integrity" "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A=="
5574 5559
   "resolved" "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz"
@@ -7728,6 +7713,16 @@
7728 7713
     "ncp" "~2.0.0"
7729 7714
     "rimraf" "~2.4.0"
7730 7715
 
7716
+"mysql@^2.18.1":
7717
+  "integrity" "sha512-Bca+gk2YWmqp2Uf6k5NFEurwY/0td0cpebAucFpY/3jhrwrVGuxU2uQFCHjU19SJfje0yQvi+rVWdq78hR5lig=="
7718
+  "resolved" "https://registry.npmjs.org/mysql/-/mysql-2.18.1.tgz"
7719
+  "version" "2.18.1"
7720
+  dependencies:
7721
+    "bignumber.js" "9.0.0"
7722
+    "readable-stream" "2.3.7"
7723
+    "safe-buffer" "5.1.2"
7724
+    "sqlstring" "2.3.1"
7725
+
7731 7726
 "mz@^2.7.0":
7732 7727
   "integrity" "sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q=="
7733 7728
   "resolved" "https://registry.npmjs.org/mz/-/mz-2.7.0.tgz"
@@ -7737,11 +7732,6 @@
7737 7732
     "object-assign" "^4.0.1"
7738 7733
     "thenify-all" "^1.0.0"
7739 7734
 
7740
-"nan@^2.12.1":
7741
-  "integrity" "sha512-2ZTgtl0nJsO0KQCjEpxcIr5D+Yv90plTitZt9JBfQvVJDS5seMl3FOvsh3+9CoYWXf/1l5OaZzzF6nDm4cagaQ=="
7742
-  "resolved" "https://registry.npmjs.org/nan/-/nan-2.17.0.tgz"
7743
-  "version" "2.17.0"
7744
-
7745 7735
 "nanoid@^3.1.23":
7746 7736
   "integrity" "sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw=="
7747 7737
   "resolved" "https://registry.npmjs.org/nanoid/-/nanoid-3.3.4.tgz"
@@ -9476,6 +9466,19 @@
9476 9466
     "string_decoder" "~1.1.1"
9477 9467
     "util-deprecate" "~1.0.1"
9478 9468
 
9469
+"readable-stream@2.3.7":
9470
+  "integrity" "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw=="
9471
+  "resolved" "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz"
9472
+  "version" "2.3.7"
9473
+  dependencies:
9474
+    "core-util-is" "~1.0.0"
9475
+    "inherits" "~2.0.3"
9476
+    "isarray" "~1.0.0"
9477
+    "process-nextick-args" "~2.0.0"
9478
+    "safe-buffer" "~5.1.1"
9479
+    "string_decoder" "~1.1.1"
9480
+    "util-deprecate" "~1.0.1"
9481
+
9479 9482
 "readdirp@^2.2.1":
9480 9483
   "integrity" "sha512-1JU/8q+VgFZyxwrJ+SVIOsh+KywWGpds3NTqikiKpDMZWScmAYyKIgqkO+ARvNWJfXeXR1zxz7aHF4u4CyH6vQ=="
9481 9484
   "resolved" "https://registry.npmjs.org/readdirp/-/readdirp-2.2.1.tgz"
@@ -10334,6 +10337,11 @@
10334 10337
   "resolved" "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz"
10335 10338
   "version" "1.0.3"
10336 10339
 
10340
+"sqlstring@2.3.1":
10341
+  "integrity" "sha512-ooAzh/7dxIG5+uDik1z/Rd1vli0+38izZhGzSa34FwR7IbelPWCCKSNIl8jlL/F7ERvy8CB2jNeM1E9i9mXMAQ=="
10342
+  "resolved" "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.1.tgz"
10343
+  "version" "2.3.1"
10344
+
10337 10345
 "ssri@^6.0.1":
10338 10346
   "integrity" "sha512-cepbSq/neFK7xB6A50KHN0xHDotYzq58wWCa5LeWqnPrHG8GzfEjO/4O8kpmcGW+oaxkvhEJCWgbgNk4/ZV93Q=="
10339 10347
   "resolved" "https://registry.npmjs.org/ssri/-/ssri-6.0.2.tgz"