# create

The .create() method for the SurrealDB Rust SDK creates one or more records in the database.

**3.x**

Creates one or more records in the database.

```rust title="Method Syntax"
db.create(resource).content(data)
```

## Arguments

<table>
    <thead>
        <tr>
            <th colspan="2" scope="col">Argument</th>
            <th colspan="2" scope="col">Type</th>
            <th colspan="2" scope="col">Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td colspan="2" scope="row" data-label="Argument">
                <code>resource</code>
            </td>
            <td colspan="2" scope="row" data-label="Description">
                The table name or the specific record ID to create.
            </td>
        </tr>
        <tr>
            <td colspan="2" scope="row" data-label="Arguments">
                <code>data</code>
            </td>
            <td colspan="2" scope="row" data-label="Description">
                The document / record data to insert.
            </td>
        </tr>
    </tbody>
</table>

## Example usage

```rust
use surrealdb::engine::any::connect;
use surrealdb::opt::auth::Root;
use surrealdb::types::{RecordId, SurrealValue};

#[derive(Debug, SurrealValue)]
struct Person {
    name: Option<String>,
    marketing: Option<bool>,
}

#[derive(Debug, SurrealValue)]
struct Record {
    id: RecordId,
}

#[tokio::main]
async fn main() -> surrealdb::Result<()> {
    let db = connect("ws://localhost:8000").await?;
    db.signin(Root {
        username: "root".to_string(),
        password: "secret".to_string(),
    })
    .await?;
    db.use_ns("main").use_db("main").await?;

    // Create a record with a random ID
    let person: Option<Person> = db.create("person").await?;
    dbg!(person);
    // Create a record with a specific ID
    let record: Option<Record> = db
        .create(("person", "tobie"))
        .content(Person {
            name: Some("Tobie".into()),
            marketing: Some(true),
        })
        .await?;
    dbg!(record);
    Ok(())
}
```

**2.x**

Creates one or more records in the database.

```rust title="Method Syntax"
db.create(resource).content(data)
```

## Arguments

<table>
    <thead>
        <tr>
            <th colspan="2" scope="col">Argument</th>
            <th colspan="2" scope="col">Type</th>
            <th colspan="2" scope="col">Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td colspan="2" scope="row" data-label="Argument">
                <code>resource</code>
            </td>
            <td colspan="2" scope="row" data-label="Description">
                The table name or the specific record ID to create.
            </td>
        </tr>
        <tr>
            <td colspan="2" scope="row" data-label="Arguments">
                <code>data</code>
            </td>
            <td colspan="2" scope="row" data-label="Description">
                The document / record data to insert.
            </td>
        </tr>
    </tbody>
</table>

## Example usage

```rust
use serde::{Deserialize, Serialize};
use surrealdb::engine::any::connect;
use surrealdb::opt::auth::Root;
use surrealdb::RecordId;

#[derive(Debug, Serialize, Deserialize)]
struct Person {
    name: Option<String>,
    marketing: Option<bool>
}

#[derive(Debug, Deserialize)]
struct Record {
    id: RecordId,
}

#[tokio::main]
async fn main() -> surrealdb::Result<()> {
    let db = connect("ws://localhost:8000").await?;
    db.signin(Root {
        username: "root",
        password: "secret",
    })
    .await?;
    db.use_ns("ns").use_db("db").await?;

    // Create a record with a random ID
    let person: Option<Person> = db.create("person").await?;
    dbg!(person);
    // Create a record with a specific ID
    let record: Option<Record> = db
        .create(("person", "tobie"))
        .content(Person {
            name: Some("Tobie".into()),
            marketing: Some(true),
        })
        .await?;
    dbg!(record);
    Ok(())
}
```

## Translated query
This function will run the following query in the database:

```surql
CREATE $resource CONTENT $data;
```

## See also

* [.create() method on Docs.rs](https://docs.rs/surrealdb/latest/surrealdb/struct.Surreal.html#method.create)
