## DAO Database
The Record Entity in our subgraphs are what we call the DAO database. These allow DAOs to create content that is indexed in out subgraphs and eliminates the need for offchain database storage.

**How does a DAO create a RECORD?**
1. Makes a proposal to call the post function on the [Poster.sol](https://github.com/onPoster/contract/blob/main/contracts/Poster.sol) for the DAOs chain. If this proposal passes the function will execute
2. A DAO member directly calls the post function on the Poster.sol contract
**The DAOHaus subgraph will index these posts into** [RECORD entites](https://hackmd.io/@bootleggers/Skfd50_w3/https%3A%2F%2Fhackmd.io%2F%40bootleggers%2FrJxLWeFPn#Record-entity).
**How does the subgraph validate the post?**
1. The TAG argument on the post function instructs the subgraph how to validate
- `daohaus.summoner.daoProfile`: post must come from the DAOhaus factory contract
- `daohaus.shares.daoProfile`: post function for a dao profile must come from a share holding address
- `daohaus.proposal.database`: post must come from a proposal execution
- `daohaus.shares.database`: post must come from a share holding address
- `daohaus.member.database`: post must come from a share or loot holding address
2. The CONTENT argument must conform to json schemas
It needs to be able to parse the json and find `daoId`, `table`, `queryType` fields.
[Valid json schemas](https://github.com/HausDAO/monorepo/blob/develop/libs/moloch-v3-data/src/subgraph/json-schemas)
Record can be used for any type of table. Right now we have indexed the following types of data:
- [DAO profiles](https://github.com/HausDAO/monorepo/blob/develop/libs/moloch-v3-data/src/subgraph/json-schemas/dao-profile.json)
- [DAO assigned credentials](https://github.com/HausDAO/monorepo/blob/develop/libs/moloch-v3-data/src/subgraph/json-schemas/credential.json)
- [DAO Signals](https://github.com/HausDAO/monorepo/blob/develop/libs/moloch-v3-data/src/subgraph/json-schemas/credential.json) and [choices](https://github.com/HausDAO/monorepo/blob/develop/libs/moloch-v3-data/src/subgraph/json-schemas/credential.json)
Using the subgraph in this way has allowed us to replace centralized databases.
### Examples
**How to create a record from a txLego**
[You can see an example of this in the DAO settings page in hte Admin app.](https://github.com/HausDAO/monorepo/blob/develop/libs/moloch-v3-legos/src/tx.ts#L324C30-L324C30)
[How to create a record from a Proposal txLego](https://github.com/HausDAO/monorepo/blob/develop/libs/moloch-v3-legos/src/tx.ts#L324C30-L324C30)
[You can see an example of this in the DAO signal proposal](https://github.com/HausDAO/monorepo/blob/develop/libs/moloch-v3-legos/src/tx.ts#L26)
**How to query a record**
Get the latest record for a 'table'
```graphql
{
records(
where: {dao: "0x0", table: "daoProfile"}
first: 1
orderBy: createdAt
orderDirection: desc
)
{
id,
content,
table
}
}
```
Get a list of records for a 'table'
```graphql
{
records(
where: {dao: "0x0", table: "signalTcrChoice"}
first: 500
)
{
id,
content,
table
}
}
```
### Record entity
```graphql
"unique identifier and primary key of the entity"
id: ID!
```
```graphql
"block timestamp when the member entity was created"
createdAt: String!
```
```graphql
"Address of the dao member creating the record"
createdBy: Bytes!
```
```graphql
"Address of the dao the record is related to"
dao: Dao!
```
```graphql
"Tag argument in the newPost function call"
tag: Bytes!
```
```graphql
"record category identifier to ease querying"
table: String!
```
```graphql
"type of content in the content field. currently this is always json"
contentType: String!
```
```graphql
"content of the record"
content: String!
```
```graphql!
"Indicates if the entities should be queried for latest or as a list"
queryType: String!
```