I am creating a hybrid app by telerik app builder in visual studio. I am not able to access sqlite db which is created externally. But I can access the db which is created at run time. I referred some sites, those solutions are not worked for me. The following code will create db and access it while run time
var app = {};
app.db = null;
app.openDb = function () {
var dbName = "Test.sqlite";
//DB creation for Simulator
if (window.navigator.simulator === true) {
app.db = window.openDatabase(dbName, "1.0", "Test Database", 1073741824);
console.log("Database Created!");
}
//DB creation for devices
else {
app.db = window.sqlitePlugin.openDatabase(dbName);
console.log("Database Accessed!");
}
}
I want to access the database which is present in the data folder. Please refer the image.
I tried to place the db in www folder and try to access it by the following code
app.db = window.sqlitePlugin.openDatabase({name: "Test.db", createFromLocation: 1});
It will give the following error
Uncaught TypeError: Cannot read property 'openDatabase' of undefined
So, how can I access the externally created sqlite db?
I included the following scripts in the project
<script src="js/jquery-2.1.0.min.js"></script>
<script src="js/angular.min.js"></script>
<script src="js/ng-cordova.min.js"></script>
It looks like your issue is that window.sqlitePlugin is undefined. Are you sure the plugin is properly installed? Also, you must wait until the deviceReady event before using window.sqlitePlugin.
Related
I want to sync a Google Sheet with my Firebase real-time database.
My code is:
function writeDataToFirebase() {
var ss =
SpreadsheetApp.openById("18AU9ZP9UHs9lvIeTA0SyJv6tcHPe7ux0tLopkRAz1T0");
var sheet = ss.getSheets()[0];
var data = sheet.getDataRange().getValues();
var dataToImport = {};
for(var i = 2; i < data.length; i++) {
var date = data[i][1];
dataToImport[date] = {
niftyclose:data[i][2],
sensexclose:data[i][5]
};
}
var firebaseUrl = "<MY database URL>"; //Yes I have entered the URL in my actual code
var base = FirebaseApp.getDatabaseByUrl(firebaseUrl);
base.setData("", dataToImport);
}
But when I run the script, I get this error:
ReferenceError: FirebaseApp is not defined
I tried adding the Firebase Library and got this error:
Firebase Library Error
Can someone help me figure this out?
Thanks in advance.
I think that MYeP8ZEEt1ylVDxS7uyg9plDOcoke7-2l is the project key. In this case, it can be used for the legacy editor. But, in the current stage, the script ID is used for installing the GAS library. And also, when you use new script editor, it is required to use the script ID for installing the library. I thought that this is the reason of your issue.
When the project key of MYeP8ZEEt1ylVDxS7uyg9plDOcoke7-2l is installed using the the legacy editor and check appsscript.json, the script ID of the library can be known. It's 1hguuh4Zx72XVC1Zldm_vTtcUUKUA6iBUOoGnJUWLfqDWx5WlOJHqYkrt. So please modify your situation as follows.
1hguuh4Zx72XVC1Zldm_vTtcUUKUA6iBUOoGnJUWLfqDWx5WlOJHqYkrt
Please install the library using above script ID. This script ID can be also seen at https://sites.google.com/site/scriptsexamples/new-connectors-to-google-services/firebase/source
References:
Libraries
Firebase
I can't get automigrate and autoupdate to work.
I created my project, datasource and model. All looks good, but I can't get automigrate to work. If I go to my SQL Server and create the table/schema then all the GET/POST methods work fine.
I went to the server/boot directory. there are currently two files in there authentication and root.
I created a new file called automigrate.js
'use strict';
module.exports = function (app) {
app.dataSources.mysql.automigrate();
console.log("Performed automigration.");
}
When I run it I get an error :
C:\Users\ajmal\loopback\telematics\server\server.js:31 if (err) throw err; ^
TypeError: Cannot read property 'automigrate' of undefined
at Object.module.exports [as func] (C:\Users\ajmal\loopback\telematics\server\boot\automigrate.js:9:26)
at C:\Users\ajmal\loopback\telematics\node_modules\loopback-boot\lib\executor.js:316:22
You can use grunt-loopback-auto module or build your own by following the document at https://loopback.io/doc/en/lb3/Creating-a-database-schema-from-models.html#auto-update
Notes:
automigrate will drop and re-create the tables. Therefore, data will be lost. It's terrible on production.
autoupdate calculates the difference between the LoopBack model and the database table definition and alters the table accordingly.
So, we should use autoupdate in almost cases.
Here is my situation : I'm developing a Chatbot on Microsoft azure platform using Node.js. For the moment the bot messages are hard-coded in .json files.
I want to improve it by using calls to a database.
I have a SQLite database file working fine (I used a browser for SQLite and made my requests). But the problem is :
How do can I use my .db file from my project ? Is this possible to somehow "read" the database file from my dialogs and then make my request to get what I need from my database ?
I know that you can call a database with the chatbot, but the issue here is that I only have the file and nothing deployed to call.
Example of what the result should give :
"Hey chatbot, tell me about Mona Lisa"
This triggers the dialogs that will ask the database : "SELECT info FROM arts WHERE arts.title LIKE '%Mona Lisa%' ";
And send the result in session.send(results).
Thanks !
Note : I'm just an intern in my company, the database file is the only thing they gave me and I have to find a solution with it
I got the solution after some research :
First you need to install sqlite3 with npm for example, then use this at the beginning of your code :
var sqlite3 = require('sqlite3').verbose();
var path = require('path');
var db_path = path.resolve(__dirname, name_Of_Your_DB);
And then work on your file with the request you need :
var db = new sqlite3.Database(db_path, sqlite3.OPEN_READONLY,(err) => {
if (err) {
return console.error(err.message);
}
//console.log("Stuff that is processed only if no error happened.");
});
var req = "YOUR REQUEST";
db.get(req, [your_parameter],(err, row) => {
if (err) {
return console.error(err.message);
}
});
db.close((err) => {
if (err) {
return console.log(err.message);
}
});
The documentation about node.js and sqlite3 is quite complete :
http://www.sqlitetutorial.net/sqlite-nodejs/query/
In my React application, I am using window object , document object and localStorage.
To avoid errors, I have set it up like:
var jsdom = require("jsdom");
var doc = jsdom.jsdom("");
if (typeof localStorage === "undefined" || localStorage === null) {
var LocalStorage = require('node-localstorage').LocalStorage;
localStorage = new LocalStorage('./scratch');
global.localStorage = localStorage;
}
var win = doc.defaultView
console.log("document default viewwwwwwwwwwwwwwwwww", doc);
global.document = doc
global.window = win
function propagateToGlobal (window) {
for (let key in window) {
if (!window.hasOwnProperty(key)) continue
if (key in global) continue
global[key] = window[key]
}
}
propagateToGlobal(win)
But in my application, I want real window, ,real localStorage and real document to be used instead of what I have set up above.
localStorage created this directory scratch.Does that mean browser localStorage would not be used now?
Also, the console statement gives this if I try to console doc variable and is being used in place of document variable which is creating problem:
Document { location: [Getter/Setter] }
This is the script I have :
<script dangerouslySetInnerHTML={{__html:(function(w,d,s,l,i){
console.log(d.getElementsByTagName(s)[0]);
w[l]=w[l]||[];
w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});
var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';
j.async=false;
j.src= '//www.googletagmanager.com/gtm.js?id='+i+dl;
console.log("f is",f);
f.parentNode ? f.parentNode.insertBefore(j,f) : false;
})(window,document,'script','dataLayer','ID')}}/>
Here getElementByTagName returns undefined and not an element as it should. How do I fix this?
basically, JSDom and the such should only be used if you would like to fake the window and document of the browser inside NodeJS. This is valid when running tests. I've not seen node-localstorage before, but i suspect the same is true of this package also.
You certainly do not want any of those packages to run within your app when on the client (in the browser).
You haven't specified which errors you have but I can only guess you are trying to run your app in node?
I would recommend removing all of them from your app completely and seeing where you get the errors. Then tackle the errors one by one. To start with ensure you only run that code on the client by using componentDidMount or something similar.
Once the app is working on the client and on the server, you could then look at how to improve / increase the amount the is rendered on the server.
I want to store some user values, name and email, in a Postgres DB on an app hosted by Heroku. This is the code in my controller;
var pg = require('pg');
...
$scope.addUser = function() {
pg.connect(process.env.DATABASE_URL, function(err, client) {
var query = client.query('INSERT INTO users (name, email) VALUES (\'' + $scope.user.name + '\', \'' + $scope.user.email + '\')');
query.on('row', function(row) {
console.log(JSON.stringify(row));
});
});
};
I get an error saying that require is not defined, which I know is because it is not supported client side. I tried using browserify on the controller file, then updating the <script> tag in the index.html that sources the file. This leads to another error.
Removing the var pg = require('pg'); gives a "ReferenceError: pg is not defined". I just want to connect to the Postgres DB from my app and insert some values. Am I on the right track or should I be going about this differently?
See Can I use PostgreSQL (pg) in the client-side (express/node.js) as to why you can't let clients connect directly to your database. You either want to write a (lightweight) server app (probably using Node.js), or you should consider a backend-as-a-service (BaaS) like Firebase or IrisCouch so that you don't need to develop the backend at all.