Skip to content

Commit

Permalink
docs(website): improve database documentation (#980)
Browse files Browse the repository at this point in the history
  • Loading branch information
pradel committed May 15, 2020
1 parent fe2e431 commit d3791bb
Show file tree
Hide file tree
Showing 15 changed files with 199 additions and 226 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<a href="https://www.npmjs.com/package/@accounts/server">
<img alt="npm" src="https://img.shields.io/npm/v/@accounts/server">
</a>
<a href="https://github.com/accounts-js/accounts/blob/master/LICENSE">
<a href="https://www.npmjs.com/package/@accounts/server">
<img alt="npm downloads" src="https://img.shields.io/npm/dm/@accounts/server">
</a>
<a href="https://codecov.io/gh/accounts-js/accounts">
Expand Down
69 changes: 11 additions & 58 deletions packages/database-mongo/README.md
Original file line number Diff line number Diff line change
@@ -1,70 +1,23 @@
# @accounts/mongo

_MongoDB adaptor for accounts_
[![npm](https://img.shields.io/npm/v/@accounts/mongo)](https://www.npmjs.com/package/@accounts/mongo)
[![npm downloads](https://img.shields.io/npm/dm/@accounts/mongo)](https://www.npmjs.com/package/@accounts/mongo)
[![codecov](https://img.shields.io/codecov/c/github/accounts-js/accounts)](https://codecov.io/gh/accounts-js/accounts)
[![License](https://img.shields.io/github/license/accounts-js/accounts)](https://github.com/accounts-js/accounts/blob/master/LICENSE)

[![npm](https://img.shields.io/npm/v/@accounts/mongo.svg?maxAge=2592000)](https://www.npmjs.com/package/@accounts/mongo)
![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)
A accounts-js database adapter for [MongoDB](https://www.mongodb.com/)

## Note
## Documentation

This package is under active development.
- [Website documentation](https://www.accountsjs.com/docs/databases/mongo)
- [API documentation](https://www.accountsjs.com/docs/api/database-mongo/globals)

## Install
## Installation

```
yarn add @accounts/mongo
```

## Usage
## Contributing

In order to use the mongo adaptor in your project, you will need to pass a valid mongo connection to `@accounts/mongo`:

```javascript
import { MongoClient } from 'mongodb';
import { AccountsServer } from '@accounts/server';
import { Mongo } from '@accounts/mongo';

// If you are using mongodb 3.x
const client = await mongodb.MongoClient.connect(process.env.MONGO_URL);
const db = client.db('my-db-name');

// If you are using mongodb 2.x
const db = await mongodb.MongoClient.connect(process.env.MONGO_URL);

const accountsMongo = new Mongo(db, options);
const accountsServer = new AccountsServer({ db: accountsMongo });

// Will create the necessary mongo indexes
await accountsMongo.setupIndexes();
```

## Usage with mongoose

If you are using mongoose in your application, you can reuse the mongoose connection like this:

```javascript
import mongoose from 'mongoose';
import { AccountsServer } from '@accounts/server';
import { Mongo } from '@accounts/mongo';

mongoose.connect(process.env.MONGO_URL);
const db = mongoose.connection;

const accountsMongo = new Mongo(db, options);
const accountsServer = new AccountsServer({ db: accountsMongo });

// Will create the necessary mongo indexes
await accountsMongo.setupIndexes();
```

The users will be saved under the `users` collection.

## Setup mongodb indexes

It's really important that your production database have the necessary mongodb indexes in order to perform fast queries.

To do so, when your server is booting, run the following command:

```javascript
await accountsMongo.setupIndexes();
```
Any contribution is very welcome, read our [contributing guide](https://github.com/accounts-js/accounts/blob/master/CONTRIBUTING.md) to see how to locally setup the repository and see our development process.
19 changes: 13 additions & 6 deletions packages/database-mongo/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
export interface AccountsMongoOptions {
/**
* The users collection name, default 'users'.
* The users collection name.
* Default 'users'.
*/
collectionName?: string;
/**
* The sessions collection name, default 'sessions'.
* The sessions collection name.
* Default 'sessions'.
*/
sessionCollectionName?: string;
/**
* The timestamps for the users and sessions collection, default 'createdAt' and 'updatedAt'.
* The timestamps for the users and sessions collection.
* Default 'createdAt' and 'updatedAt'.
*/
timestamps?: {
createdAt: string;
updatedAt: string;
};
/**
* Should the user collection use _id as string or ObjectId, default 'true'.
* Should the user collection use _id as string or ObjectId.
* Default 'true'.
*/
convertUserIdToMongoObjectId?: boolean;
/**
* Should the session collection use _id as string or ObjectId, default 'true'.
* Should the session collection use _id as string or ObjectId.
* Default 'true'.
*/
convertSessionIdToMongoObjectId?: boolean;
/**
* Perform case intensitive query for user name, default 'true'.
* Perform case intensitive query for user name.
* Default 'true'.
*/
caseSensitiveUserName?: boolean;
/**
Expand All @@ -32,6 +38,7 @@ export interface AccountsMongoOptions {
idProvider?: () => string | object;
/**
* Function that generate the date for the timestamps.
* Default to `(date?: Date) => (date ? date.getTime() : Date.now())`.
*/
dateProvider?: (date?: Date) => any;
}
Expand Down
39 changes: 15 additions & 24 deletions packages/database-redis/README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,25 @@
# @accounts/redis

_Redis adaptor for accounts_
[![npm](https://img.shields.io/npm/v/@accounts/redis)](https://www.npmjs.com/package/@accounts/redis)
[![npm downloads](https://img.shields.io/npm/dm/@accounts/redis)](https://www.npmjs.com/package/@accounts/redis)
[![codecov](https://img.shields.io/codecov/c/github/accounts-js/accounts)](https://codecov.io/gh/accounts-js/accounts)
[![License](https://img.shields.io/github/license/accounts-js/accounts)](https://github.com/accounts-js/accounts/blob/master/LICENSE)

[![npm](https://img.shields.io/npm/v/@accounts/redis.svg?maxAge=2592000)](https://www.npmjs.com/package/@accounts/redis)
![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)
A database adapter for [Redis](https://redis.io/)

## Install
> For now `@accounts/redis` only provide a session storage, you will need to use another connector for the user storage.
```
yarn add @accounts/redis
```

## Usage

```javascript
import IORedis from 'ioredis';
## Documentation

import { AccountsServer } from '@accounts/server';
import { DatabaseManager } from '@accounts/database-manager';
import { RedisSessions } from '@accounts/redis';
- [Website documentation](https://www.accountsjs.com/docs/databases/redis)
- [API documentation](https://www.accountsjs.com/docs/api/database-redis/globals)

const ioRedis = new IORedis();
## Installation

const sessionDb = new RedisSessions(ioRedis, {
...options,
});
```
yarn add @accounts/redis
```

const accountsDb = new DatabaseManager({
sessionStorage: sessionDb,
});
## Contributing

const accountsServer = new AccountsServer({ db: accountsDb });
```
Any contribution is very welcome, read our [contributing guide](https://github.com/accounts-js/accounts/blob/master/CONTRIBUTING.
10 changes: 7 additions & 3 deletions packages/database-redis/src/types/options.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
export interface AccountsRedisOptions {
/**
* The users collection name, default 'users'.
* The users collection name.
* Default 'users'.
*/
userCollectionName?: string;
/**
* The sessions collection name, default 'sessions'.
* The sessions collection name.
* Default 'sessions'.
*/
sessionCollectionName?: string;
/**
* The timestamps for the users and sessions collection, default 'createdAt' and 'updatedAt'.
* The timestamps for the users and sessions collection.
* Default 'createdAt' and 'updatedAt'.
*/
timestamps?: {
createdAt: string;
Expand All @@ -21,6 +24,7 @@ export interface AccountsRedisOptions {
idProvider?: () => string;
/**
* Function that generate the date for the timestamps.
* Default to `(date?: Date) => (date ? date.getTime() : Date.now())`.
*/
dateProvider?: (date?: Date) => any;
}
65 changes: 11 additions & 54 deletions packages/database-typeorm/README.md
Original file line number Diff line number Diff line change
@@ -1,66 +1,23 @@
# @accounts/typeorm

_TypeORM adaptor for accounts_
[![npm](https://img.shields.io/npm/v/@accounts/typeorm)](https://www.npmjs.com/package/@accounts/typeorm)
[![npm downloads](https://img.shields.io/npm/dm/@accounts/typeorm)](https://www.npmjs.com/package/@accounts/typeorm)
[![codecov](https://img.shields.io/codecov/c/github/accounts-js/accounts)](https://codecov.io/gh/accounts-js/accounts)
[![License](https://img.shields.io/github/license/accounts-js/accounts)](https://github.com/accounts-js/accounts/blob/master/LICENSE)

[![npm](https://img.shields.io/npm/v/@accounts/typeorm.svg?maxAge=2592000)](https://www.npmjs.com/package/@accounts/typeorm)
![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)
A database adapter for [PostgreSQL](https://www.postgresql.org/) using [TypeORM](https://typeorm.io/)

## Note
## Documentation

This package is under active development.
- [Website documentation](https://www.accountsjs.com/docs/databases/typeorm)
- [API documentation](https://www.accountsjs.com/docs/api/database-typeorm/globals)

## Install
## Installation

```
yarn add @accounts/typeorm
```

## Usage
## Contributing

```javascript
import { createConnection } from 'typeorm';
import { AccountsServer } from '@accounts/server';
import { AccountsTypeorm, entities } from '@accounts/typeorm';

createConnection({
type: 'postgres',
url: 'postgres://user@localhost:5432/dbname',
entities,
}).then(() => {
const accountsTypeorm = new Typeorm();
const accountsServer = new AccountsServer({ db: accountsTypeorm });
});
```

## Options

```ts
type Options = {
cache?: undefined | number; // Cache results from database (in ms)
connection?: Connection; // Pass a connection instance
connectionName?: string; // Use a connection name (if other than "default")
userEntity?: typeof User; // Overwrite entities with your own
userServiceEntity?: typeof UserService;
userEmailEntity?: typeof UserEmail;
userSessionEntity?: typeof UserSession;
};
```

### Extending entities

If you want to add fields, etc. to the User entity you can, by extending the base entities.

```tsx
import { User as AccountsUser } from '@accounts/typeorm';

@Entity()
export class User extends AccountsUser {
// Add fields
@Column()
custom_field: string;

// Overwrite fields
@Colum('text')
profile: string;
}
```
Any contribution is very welcome, read our [contributing guide](https://github.com/accounts-js/accounts/blob/master/CONTRIBUTING.md) to see how to locally setup the repository and see our development process.
1 change: 1 addition & 0 deletions packages/oauth-instagram/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# @accounts/oauth-instagram
1 change: 1 addition & 0 deletions packages/oauth-twitter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# @accounts/oauth-twitter
1 change: 1 addition & 0 deletions packages/oauth/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# @accounts/oauth
4 changes: 4 additions & 0 deletions packages/two-factor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# @accounts/two-factor

[![npm](https://img.shields.io/npm/v/@accounts/two-factor.svg)](https://www.npmjs.com/package/@accounts/two-factor)
![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)

0 comments on commit d3791bb

Please sign in to comment.