Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 01c2c54

Browse files
#132 [Feature request] Get Firebase timestamp
1 parent be324e0 commit 01c2c54

File tree

6 files changed

+93
-64
lines changed

6 files changed

+93
-64
lines changed

docs/DATABASE.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@ If you want to add data to a known path use this, otherwise use `push` (see belo
2626
The plugin will take care of serializing JSON data to native data structures.
2727

2828
```js
29-
3029
// to store a JSON object
3130
firebase.setValue(
3231
'/companies',
33-
{'foo':'bar'}
32+
{foo:'bar'}
3433
);
3534

3635
// to store an array of JSON objects
@@ -43,6 +42,21 @@ The plugin will take care of serializing JSON data to native data structures.
4342
);
4443
```
4544

45+
#### Adding an update timestamp
46+
If you want to have Firebase a timestamp to your data (instead of clients which likely are not synchronized),
47+
you can use the placeholder value `firebase.ServerValue.TIMESTAMP`, so for instance:
48+
49+
```js
50+
// to store a JSON object
51+
firebase.setValue(
52+
'/companies',
53+
{
54+
foo: 'bar',
55+
updateTs: firebase.ServerValue.TIMESTAMP
56+
}
57+
);
58+
```
59+
4660
### push
4761
This function will store a JSON object at path `<Firebase URL>/users/<Generated Key>`
4862

firebase-common.d.ts

Lines changed: 0 additions & 59 deletions
This file was deleted.

firebase.android.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ firebase.init = function (arg) {
123123
return;
124124
}
125125

126+
firebase.ServerValue = {
127+
TIMESTAMP: firebase.toJsObject(com.google.firebase.database.ServerValue.TIMESTAMP)
128+
};
129+
126130
var fDatabase = com.google.firebase.database.FirebaseDatabase;
127131
if (arg.persist) {
128132
fDatabase.getInstance().setPersistenceEnabled(true);

firebase.d.ts

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,70 @@
1-
/// <reference path="firebase-common.d.ts"/>
2-
declare module "nativescript-plugin-firebase" {
1+
declare module "nativescript-firebase" {
2+
3+
/**
4+
* The allowed values for LoginOptions.type.
5+
*/
6+
export enum LoginType {
7+
/**
8+
* No further data is required.
9+
*/
10+
ANONYMOUS,
11+
/**
12+
* This requires you to pass in email and password properties as well.
13+
*/
14+
PASSWORD,
15+
/**
16+
* This requires you to pass either an authentication token generated by your backend server
17+
* or the tokenProviderFn function that returns a promise to provide the token.
18+
* See: https://firebase.google.com/docs/auth/server
19+
*/
20+
CUSTOM,
21+
/**
22+
* This requires you to setup Facebook Auth in the Firebase console,
23+
* as well as uncommenting the SDK includes in include.gradle (Android) and Podfile (iOS).
24+
*/
25+
FACEBOOK,
26+
/**
27+
* This requires you to setup Google Sign In in the Firebase console,
28+
* as well as uncommenting the SDK includes in include.gradle (Android) and Podfile (iOS).
29+
*/
30+
GOOGLE
31+
}
32+
33+
/**
34+
* The allowed values for QueryOptions.orderBy.type.
35+
*/
36+
export enum QueryOrderByType {
37+
KEY,
38+
VALUE,
39+
CHILD,
40+
PRIORITY
41+
}
42+
43+
/**
44+
* The allowed values for QueryOptions.range.type.
45+
*/
46+
export enum QueryRangeType {
47+
START_AT,
48+
END_AT,
49+
EQUAL_TO
50+
}
51+
52+
/**
53+
* The allowed values for QueryOptions.limit.type.
54+
*/
55+
export enum QueryLimitType {
56+
FIRST,
57+
LAST
58+
}
59+
60+
export interface ServerValue {
61+
/**
62+
* When for instance using setValue you can set a timestamp property to this placeholder value.
63+
* Example:
64+
* updateTs: firebase.ServerValue.TIMESTAMP
65+
*/
66+
TIMESTAMP: any;
67+
}
368

469
/**
570
* The options object passed into the init function.

firebase.ios.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ firebase.init = function (arg) {
300300
return;
301301
}
302302

303+
firebase.ServerValue = {
304+
TIMESTAMP: FIRServerValue.timestamp()
305+
};
306+
303307
// this requires you to download GoogleService-Info.plist and
304308
// it to app/App_Resources/iOS/, see https://firebase.google.com/support/guides/firebase-ios
305309
FIRApp.configure();

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"name": "nativescript-plugin-firebase",
3-
"version": "3.6.3",
3+
"version": "3.6.4-dev",
44
"description" : "Fire. Base. Firebase!",
55
"main" : "firebase.js",
6+
"typings": "firebase.d.ts",
67
"nativescript": {
78
"platforms": {
89
"android": "2.3.0",

0 commit comments

Comments
 (0)