pring.ts
Firebase Cloud Firestore model framework for TypeScript.
Installation ⚙
npm install pring --save
Usage
TypeScript
required
"devDependencies": { "@types/node": "^10.9.2", "typescript": "^3.0.3" },
tsconfig.json
{ "compilerOptions": { "target": "es6", "module": "esnext", "strict": true, "jsx": "preserve", "importHelpers": true, "moduleResolution": "node", "experimentalDecorators": true, "esModuleInterop": true, "allowSyntheticDefaultImports": true, "sourceMap": true, "baseUrl": ".", "types": [ "node" ], "paths": { "@/*": [ "src/*" ] }, "lib": [ "esnext", "dom", "dom.iterable", "scripthost" ] }, "include": [ "src/**/*.ts", "src/**/*.tsx", "src/**/*.vue", "tests/**/*.ts", "tests/**/*.tsx" ], "exclude": [ "node_modules" ]}
webpack.config.js
const alias = moduleexports = // ... resolve: alias
Initialize
When using Pring in Vue please include it in main.ts
.
For Web
Pring.initializeapp.firestore
Scheme
- Please add
@property
for property declaration. - SubCollection can not be optional. Please initialize here.
Manage data
Initialize
// auto generate ID// any ID// any ID, Handle already saved users
memo
The developer is responsible for managing the Document being saved. In Pring it is prohibited to save the already saved Document again.
Please use explicitly by the initialization method.
new User("YOUR_ID", {})
let user = new User("YOUR_ID")
Save
user.name = "hoge"await user.save
Get
Update
user.name = "UPDATE NAME"await user.update
user.name = "UPDATE NAME"await user.update
Delete
await user.delete
SubCollection
You can use ReferenceCollection and NestedCollection. The inserted Object is saved simultaneously with the save of the parent.
user.groups.insertgroupawait user.save
If you insert the parent after it is saved, you need to use await
to guarantee the count of SubCollection.
await user.savetrycatcherror
DataSource
DataSource is a class that controls Collection of Firestore.
Test
https://facebook.github.io/jest/
npm install -g jest
jest