> For the complete documentation index, see [llms.txt](https://docs.ask.edvard.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ask.edvard.dev/database/database-lists.md).

# Database Lists

Storing lists in the context of databases can be challenging. The easiest way to overcome this is to restructure your project to use multiple models and link them together with ids. Though this method might still be a bit complex. So, to solve this problem Ask has built-in database models ready to go for storing a list (list-like) objects.

The built-in database model is called `List` and it can be used along with the database column data type `list_id` (which is just an alias for `int`, but it improves readability) to link it in a table.

## Create a DB List

```python
my_list = db.list([1, 2, 3, 4])  # The passed in list is optional.
```

This will automatically also add the row to the database.

## Properties of the List Object

{% tabs %}
{% tab title=".list()" %}

* Basically a serialization method.
* Returns a standard list.
* Note! Don't mutate the return value of this method, it won't update the list in the database.

**Example:**

```python
my_list = db.list(['a', 'b', 'c'])
my_list.list()  # ['a', 'b', 'c']
```

{% endtab %}

{% tab title=".get()" %}

* Takes in an integer.
* Returns a single item from the list by index number.

**Example:**

```python
my_list = db.list(['a', 'b', 'c'])
my_list.get(1)  # 'b'
```

{% endtab %}

{% tab title=".push()" %}

* Append to the list.

**Example:**

```python
my_list = db.list(['a', 'b', 'c'])
my_list.push('d')
my_list.list()  # ['a', 'b', 'c', 'd']
```

{% endtab %}

{% tab title=".remove()" %}

* Remove an element from the list.
* Takes in an integer.
* Removes by index number.

**Example:**

```python
my_list = db.list(['a', 'b', 'c'])
my_list.remove(1)
my_list.list()  # ['a', 'c']
```

{% endtab %}

{% tab title=".set\_list()" %}

* Overwrite the list with a new one.
* Takes in a list.

**Example:**

```python
my_list = db.list(['a', 'b', 'c'])
my_list.list()  # ['a', 'b', 'c']
my_list.set_list([1, 2, 3])
my_list.list()  # [1, 2, 3]
```

{% endtab %}
{% endtabs %}


---

# 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:

```
GET https://docs.ask.edvard.dev/database/database-lists.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
