I'm developing a Xamarin.Forms app which uses an Azure app service with SQL database linked through EasyTables. I've run the samples and successfully tested querying tables etc on the server and enabled offline sync so as a localdb is created.
I've created the store, defined the table & sync'd it, however I want to be able to query it somehow with a where clause - is that possible? Can I add a where clause to the client.GetSyncTable line?
var store = new MobileServiceSQLiteStore("localstore.db");
store.DefineTable<Journey_Stages>();
client.SyncContext.InitializeAsync(store);
tbl_Stages = client.GetSyncTable<Journey_Stages>();
Some of the tables I'm pulling down will grow over time & are linked to individual user profiles, so I only want data which belongs to that user and I don't want to be bringing down masses of data each time, preferably let the server handle that and only bring down what I need on a user by user basis.
Thanks,
Steve
You should add this filtering logic on the server side, so that each user's data isn't exposed to all your other users. See for example this sample if you are using the Node.js backend -- line 17 adds a WHERE clause for the table read query. If you have the .Net backend, similar logic would go in your table controller.
// Configure specific code when the client does a request
// READ - only return records belonging to the authenticated user
table.read(function (context) {
context.query.where({ userId: context.user.id });
return context.execute();
});
Related
I'm working on an Angular2 project (Resource Management) which requires data from the database (mongoDB) in real time. The basic function of the application is to drag a resource from bench and drop it to a project. After which a button is clicked which saves these values to the database. The problem is once the database is hit with the values, the same is not showing up unless the page is refreshed. Is there a way where we can pull data from the database without manually refreshing the entire page or pulling the data from DB at regular intervals so that the services have the latest data. I'm attaching my code here: Resource Management (drag n drop)
Thank you!!
If you want to get the data periodically.You can use timer.
ngOnInit() {
this.timer = Observable.timer(2000,5000);
// subscribing to a observable returns a subscription object
this.sub = this.timer.subscribe(t => this.geData(t));
}
geData(t) {
console.log(t)
}
You Could use socket.io for real time update with angular2 and mongodb
After reading the documentation I was expecting that this field is automatically set by Azure Mobile Services. Apparently it isn't.
Should I configure something extra?
Other options that I see (to do for each table):
* add an axtra line to the node js update(item, user, request) function:
item.__updatedAt = new Date();
* create an update trigger in the database
Anybody experience with this?
Thx!
The __updatedAt column is updated by a trigger created in the underlying SQL Server database, so it should be updated any time a row is updated. Note that this requires a database operation to occur for it to be updated.
I am currently working on an inventory management software in Node js and MongoDB. I am pretty new to MongoDB, having worked in Oracle and MySQL for most of my projects.
Is it possible to create a separate database schema for every client who uses my software, with each client having access only to his copy of the database schema and collections?
The equivalent of selecting data in Oracle database would be
Select * from User1.table,
Select * from User2.table etc
Also, if it were possible, how would it be implemented using a node js mongo db client like mongoose?
I looked at MongoDB documentation, but it talks mainly about adding users to a database for authorization.
I apologize if it seems like a silly question, but id appreciate it if someone could point me in the right direction for this.
Before starting to invest a lot of time in the development of your project, check out other possible approaches to the scenario that you are trying to build.
I did a quick search on SO and found some additional threads with similar scenarios:
MongoDB Database vs. Collection
MongoDB Web App - Database per User
Additional info about mongoose database creation
Whenever you call the connect method on the mongoose object, you are either connecting to an existing database or you are creating it in case it doesn't already exist.
You could have a function that allows you to pass in a name argument with the name and create databases programmatically:
function createDatabase(name) {
var conn_string = 'mongodb://localhost/';
if (typeof name == 'string') {
conn_string += name;
}else{
return false;
}
mongoose.connect(conn_string);
}
Also, be aware that a database will be created when you first insert a record in a collection of that particular database.
It is not sufficient to only connect to the database, you also have to insert a record.
As per my previous example, you could also pass a schema parameter to the function, tailored to each user's profile and fire an insert statement after you connect to that database.
I have created standard dashboards connected to a single schema.
Now I would like to re-use the same dashboards definition on different schemas. These schemas are all equivalent (same dimensions, measures, but different client data).
Is this possible?
I think of the process sequence:
user logs on, dashboards connects to schema defined in the dashboard
if the user has no access to this schema, connect to the schema the user has access to
allow a user to select from the schemas to which he/she is authorized
You can do that when opening a report using the javascript API. Somehow, you would have an instance of ic3.Reporting.
var ic3reporting = new ic3.Reporting();
Then before opening the report you can register an event to listen when its definition is received:
ic3reporting.bind(vizEventType.onReportJSON, function(ic3report){
ic3report.schemaName("...");
});
In the callback function you get the opportunity to change the name of the schema being used by this report.
[edit: vizEventType.onReportJSON is actually the string 'ic3reportJSON']
When we create a new table in Azure Mobile Services Data, it creates a [__deleted] column along with others like [__createdAt] etc. This is good, in case if I have to soft delete a record, I set _deleted = true, instead of permanently deleting it.
My question is, when we query a MobileServices table say from client side or in server scripts using table.read or mssql.query, do I need to specify __deleted=false in each read/query explicitly or is there any app level config/setting available in MobileServices that we can set so that it doesn't return the records with __deleted=true by default.
By default, queries going through the standard path (formed via client or server table.read) should filter deleted records. (Essentially a __deleted = false clause will be added for you)
To get deleted records from the client you can send the __includeDeleted querystring parameter or on server you can use table.read({includeDeleted: true, ...) This will disable that default clause from being added.