> For the complete documentation index, see [llms.txt](https://ng-girls.gitbook.io/todo-list-tutorial/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ng-girls.gitbook.io/todo-list-tutorial/more-workshops/index/06_connect_database.md).

# #6 ⚙️Connect Database

## Create custom pipes

We will add two custom pipes in our app

* **Excerpt**: which will show a summary of post in blog card.
* **Slug**: which will show the URL slug for a post.

We will create a a new pipe named ExcerptPipe. Right-click on the folder 📁`custompipes` and then navigate to 'Angular Generator', select 'Pipe' and provide the name ‘excerpt.

Replace the `transform` method in the file 📝 `src/app/custompipes/excerpt.pipe.ts` with the following code :

```
transform(content: string) {
    const postSummary = content.replace(/(<([^>]+)>)/ig, '');
    if (postSummary.length > 300) {
    return postSummary.substr(0, 300) + ' [...]';
    } else {
    return postSummary;
    }
}
```

Furthermor we create a slug pipe. Right-click on the folder 📁`custompipes` and then navigate to 'Angular Generator', select 'Pipe' and provide the name ‘slug’.

Replace the `transform` method in the file 📝 `src/app/custompipes/slug.pipe.ts` with the following code:

```
transform(title: string) {
    const urlSlug = title.trim().toLowerCase().replace(/ /g, '-');
    return urlSlug;
}
```

## Get the blogs from database

We will add the `getAllPosts` method in 📝`src/app/services/blog.service.ts` file to fetch all the blog posts from database. The definition for `getAllPosts` is shown at [blog.service.ts (Github)](https://github.com/ng-girls/todo-list-tutorial/blob/master/workshops/blog-editor/code/06-services/blog.service.ts#L19-L29)

```
getAllPosts(): Observable<any> {
    const blogs = this.db.collection('blogs', ref => ref.orderBy('createdDate', 'desc')).snapshotChanges().pipe(
    map(actions => {
        return actions.map(
        c => ({
            postId: c.payload.doc.id,
            ...c.payload.doc.data()
        }));
    }));
    return blogs;
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ng-girls.gitbook.io/todo-list-tutorial/more-workshops/index/06_connect_database.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
