> For the complete documentation index, see [llms.txt](https://docs.schemajs.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.schemajs.com/getting-started/hello-world.md).

# Hello World

Also known as "Your First Table"

{% hint style="info" %}
Read about ["Setting up your environment"](/getting-started/setting-up-your-environment.md) before writing your first table.
{% endhint %}

## Content

* You will create a table called `books`
* You will insert a row
* You will query the inserted row

## Example Table

After having set-up your environment, we will create a table called **books.** For this, we will create a file named `books.ts` inside your `tables` folder. It will look like this:

{% code title="./public/tables/books.ts" %}

```typescript
export default function main() {
    const { Table, Column } = SchemaJS;
    return new Table("books")
        .addColumn(new Column("id").string())
        .addColumn(new Column("name").string())
        .addColumn(new Column("author").string())
}
```

{% endcode %}

## Insert a row

After having created our table, we will run the engine by executing the following terminal command from the root of where our `SchemaJS.toml` is.

```
schemajs start
```

<div align="left" data-full-width="false"><figure><img src="https://3857732323-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgNrwDrQ1Jjmi890Wdo6L%2Fuploads%2FGHmkIHxv4Y8RC7rBpaeS%2Fout.png?alt=media&amp;token=2dbac1c4-f1ad-40ab-80e9-6be6a40fb3e8" alt="" width="188"><figcaption></figcaption></figure></div>

***

> Running `start` will open up a REPL after having initialized our database.

In our REPL, we will type `use` to access the table. For this, we will first need to access the database and then the table context.

`use("public")`

`use("books")`

<div align="left"><figure><img src="https://3857732323-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgNrwDrQ1Jjmi890Wdo6L%2Fuploads%2FfZr0YdBpWiZzeWLZqwn8%2Fimage.png?alt=media&amp;token=cc304d0b-3f0c-407f-a3f8-0b58266b8ac0" alt="" width="188"><figcaption></figcaption></figure></div>

and finally, after being in the context of the table **books,** we will proceed to run the following Javascript code.

```javascript
SchemaJS.insert({ id: "SOME-ID", "name": "The Lord of the Rings", "author": "J.R.R Tolkien" });
```

## Querying a row

Finally, to query a row, we can run the following JS command:

```javascript
SchemaJS.query(
  new SchemaJS.QueryBuilder()
    .and((and) => and.where("author", "=", "The Lord of the Rings"))
)
.then((res) => {
  SchemaJS.print(JSON.stringify(res));
});
```

<figure><img src="https://3857732323-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgNrwDrQ1Jjmi890Wdo6L%2Fuploads%2FL5HCCtBetdnH0kLfTNQD%2Fout.png?alt=media&amp;token=dd34a134-9fdd-450b-8d20-a38a877711cb" alt=""><figcaption></figcaption></figure>
