# Introduction

Daita Instruction

## [<img src="/files/tjlUWip46fm5wjF5c0D2" alt="daita" data-size="line">](https://daita.ch) TLDR

Daita provides an easy way to interact with relational databases. It's goal is to provide the full flexibility of sql within the typescript syntax to provide the best developer experience.

```typescript
// fetch the 5 highest mountains
const mountains = await client.select({
    select: {
       mountain: field(Mountain, 'name'),
       height: field(Moutain, 'height'),
    },
    from: table(Mountain),
    orderBy: desc(field(Moutain, 'height')),
    limit: 5,
})
// const mountains: { mountain: string, height: number }[]
```

### Quick Overview

Daita contains different multiple modules with different purposes. They build on top of each other, but can be used independently.

![Daita overview](/files/CQ5cJoMVogwpT882qYs8)

* **Postgres / SQLite / MariaDB Adapter**

  Database drivers for connecting, formatting and executing sql commands.
* **Http Adapter**

  Database proxy to use relational databases over HTTP.
* **Relational**

  SQL Language interfaces and query builder functions.
* **ORM**

  Schema definition and data migrations with support for schemas, tables, indices and views.
* **cli**

  Setting up new projects, generating and applying database migrations.
* **eslint**

  Enforcing best practices and preventing invalid sql queries.


# Getting started

```
npm init @daita
```

```
export class Mountain {
  name!: string
  height!: number
}
```

```
import { RelationalSchema } from '@daita/orm';
import { Mountain } from './models/mountain';

export const schema = new RelationalSchema('getting-started');
schema.table(Mountain);
```

```
npx daita migration:add initial
```

```
npx daita migration:apply
```


# Usage


# relational


# SELECT

Select

## SELECT

### field

```typescript
const names = await client.select({
   select: field(Moutain, 'name'),
   from: table(Mountain),
});
// sql: SELECT "Mountain"."name" FROM "Mountain"
//
// const names: string[]
```

```typescript
const mountains = await client.select({
   select: { 
     moutain: field(Moutain, 'name'),
   }
   from: table(Mountain),
});
// sql: SELECT "Mountain"."name" FROM "Mountain"
//
// const names: { mountain: string }[]
```

### all (\*)

```typescript
const mountains = await client.select({
  select: all(Mountain),
  from: table(Mountain),
});
// sql: SELECT "Mountain".* FROM "Mountain"
//
// const mountains: Mountain[]
```

```typescript
const mountains = await client.select({
  select: all(),
  from: table(Mountain),
});
// sql: SELECT * FROM "Mountain"
//
// const mountains: any[]
```

### subSelect

```typescript
const mountains = await client.select({
  select: {
    name: field(Moutain, 'name'),
    firstAscent: subSelect({
      select: min(field(Ascent, 'date')),
      from: table(Ascent),
      where: equal(field(Ascent, 'mountain'), field(Mountain, 'name'))
    }),
  },
  from: table(Mountain),
});
// sql: SELECT 
//         "Mountain"."name", 
//         (SELECT min("Ascent"."date") FROM "Ascent" WHERE "Ascent"."mountain" = "Mountain"."name")) 
//      FROM "Mountain"
//
// const mountains: { name: string, firstAscent: Date }[]
```

### selectFirst

```typescript
const mountains = await client.selectFirst({
  select: all(Mountain),
  from: table(Mountain),
});
// sql: SELECT "Mountain".* FROM "Mountain" LIMIT 1
//
// const mountains: Mountain
```

## FROM

### table

```typescript
const mountains = await client.select({
   select: field(Moutain, 'name'),
   from: table(Mountain),
});
// sql: SELECT "Mountain"."name" FROM "Mountain"
//
// const mountains: string[]
```

### alias

```typescript
const mountainAlias = alias(table(Mountain), 'm')
const mountains = await client.select({
   select: field(mountainAlias, 'name'),
   from: mountainAlias,
});
// sql: SELECT "m"."name" FROM "Mountain" "m"
//
// const mountains: string[]
```

### subSelect

```typescript
const mountainSubSelect = subSelect({
   select: {
      country: field(Mountain, 'country'),
      count: count()
   },
   from: table(Mountain),
   groupBy: field(Mountain, 'country'),
});
const moutainSubSelectAlias = alias(mountainSubSelect, 'm')
const mountains = await client.select({
   select: field(moutainSubSelectAlias, 'country'),
   from: moutainSubSelectAlias,
   where: greaterThan(field(moutainSubSelectAlias, 'count'), 10),
});
// sql: SELECT "m"."country" 
//      FROM (
//        SELECT "Mountain"."country", count(*) 
//        FROM "Mountain" 
//        GROUP BY "Mountain"."country"
//      ) "m"
//      WHERE "m"."count" > 10  
//
// const mountains: string[]
```

## JOIN

### join

```typescript
const mountains = await client.select({
   select: {
     mountain: field(Moutain, 'name'),
     date: field(Ascent, 'date'),
   },
   from: table(Mountain),
   join: [
     join(Ascent, equal(field(Mountain, 'firstAscent'), field(Ascent, 'id')))
   ],
});
// sql: SELECT "Mountain"."name", "Mountain"."country" 
//      FROM "Mountain"
//      JOIN "Mountain"."firstAscent" = "Ascent"."id"
//
// const mountains: { country: string, mountain: number }[]
```

### leftJoin

```typescript
const mountains = await client.select({
   select: {
     mountain: field(Moutain, 'name'),
     date: field(Ascent, 'date'),
   },
   from: table(Mountain),
   join: [
     leftJoin(Ascent, equal(field(Mountain, 'firstAscent'), field(Ascent, 'id')))
   ],
});
// sql: SELECT "Mountain"."name", "Mountain"."country" 
//      FROM "Mountain"
//      LEFT JOIN "Mountain"."firstAscent" = "Ascent"."id"
//
// const mountains: { country: string, mountain: number }[]
```

### rightJoin

```typescript
const mountains = await client.select({
   select: {
     mountain: field(Moutain, 'name'),
     date: field(Ascent, 'date'),
   },
   from: table(Mountain),
   join: [
     rightJoin(Ascent, equal(field(Mountain, 'firstAscent'), field(Ascent, 'id')))
   ],
});
// sql: SELECT "Mountain"."name", "Mountain"."country" 
//      FROM "Mountain"
//      RIGHT JOIN "Mountain"."firstAscent" = "Ascent"."id"
//
// const mountains: { country: string, mountain: number }[]
```

## WHERE

### equal

```typescript
const mountains = await client.select({
   select: {
     country: field(Moutain, 'country'),
     mountain: field(Moutain, 'name'),
   },
   from: table(Mountain),
   where: equal(field(Mountain, 'country'), 'CH'),
});
// sql: SELECT "Mountain"."name", "Mountain"."country" 
//      FROM "Mountain"
//      WHERE "Mountain"."country" = 'CH'
//
// const mountains: { country: string, mountain: number }[]
```

### notEqual

```typescript
const mountains = await client.select({
   select: {
     country: field(Moutain, 'country'),
     mountain: field(Moutain, 'name'),
   },
   from: table(Mountain),
   where: notEqual(field(Mountain, 'country'), 'CH'),
});
// sql: SELECT "Mountain"."name", "Mountain"."country" 
//      FROM "Mountain"
//      WHERE "Mountain"."country" != 'CH'
//
// const mountains: { country: string, mountain: number }[]
```

### greaterThan

```typescript
const mountains = await client.select({
   select: field(Moutain, 'name'),
   from: table(Mountain),
   where: greaterThan(field(Mountain, 'height'), 1000),
});
// sql: SELECT "Mountain"."name"
//      FROM "Mountain"
//      WHERE "Mountain"."height" > 1000
//
// const mountains: string[]
```

### greaterEqualThan

```typescript
const mountains = await client.select({
   select: field(Moutain, 'name'),
   from: table(Mountain),
   where: greaterEqualThan(field(Mountain, 'height'), 1000),
});
// sql: SELECT "Mountain"."name"
//      FROM "Mountain"
//      WHERE "Mountain"."height" >= 1000
//
// const mountains: string[]
```

### lowerThan

```typescript
const mountains = await client.select({
   select: field(Moutain, 'name'),
   from: table(Mountain),
   where: lowerThan(field(Mountain, 'height'), 1000),
});
// sql: SELECT "Mountain"."name"
//      FROM "Mountain"
//      WHERE "Mountain"."height" < 1000
//
// const mountains: string[]
```

### lowerEqualThan

```typescript
const mountains = await client.select({
   select: field(Moutain, 'name'),
   from: table(Mountain),
   where: lowerEqualThan(field(Mountain, 'height'), 1000),
});
// sql: SELECT "Mountain"."name"
//      FROM "Mountain"
//      WHERE "Mountain"."height" <= 1000
//
// const mountains: string[]
```

### isNull

```typescript
const mountains = await client.select({
   select: field(Moutain, 'name'),
   from: table(Mountain),
   where: isNull(field(Mountain, 'firstAscent')),
});
// sql: SELECT "Mountain"."name"
//      FROM "Mountain"
//      WHERE "Mountain"."firstAscent" IS NULL
//
// const mountains: string[]
```

### isNotNull

```typescript
const mountains = await client.select({
   select: field(Moutain, 'name'),
   from: table(Mountain),
   where: isNotNull(field(Mountain, 'firstAscent')),
});
// sql: SELECT "Mountain"."name"
//      FROM "Mountain"
//      WHERE "Mountain"."firstAscent" IS NOT NULL
//
// const mountains: string[]
```

### in

```typescript
const mountains = await client.select({
   select: field(Moutain, 'name'),
   from: table(Mountain),
   where: isIn(field(Mountain, 'country'), ['CH', 'IT']),
});
// sql: SELECT "Mountain"."name"
//      FROM "Mountain"
//      WHERE "Mountain"."country" IN ('CH', 'IT')
//
// const mountains: string[]
```

### isNotIn

```typescript
const mountains = await client.select({
   select: field(Moutain, 'name'),
   from: table(Mountain),
   where: isNotIn(field(Mountain, 'country'), ['CH', 'IT']),
});
// sql: SELECT "Mountain"."name"
//      FROM "Mountain"
//      WHERE "Mountain"."country" NOT IN ('CH', 'IT')
//
// const mountains: string[]
```

### like

```typescript
const mountains = await client.select({
   select: field(Moutain, 'name'),
   from: table(Mountain),
   where: like(field(Mountain, 'name'), 'Matter%'),
});
// sql: SELECT "Mountain"."name"
//      FROM "Mountain"
//      WHERE "Mountain"."name" LIKE 'Matter%'
//
// const mountains: string[]
```

### between

```typescript
const mountains = await client.select({
   select: field(Moutain, 'name'),
   from: table(Mountain),
   where: between(field(Mountain, 'height'), 1000, 2000),
});
// sql: SELECT "Mountain"."name"
//      FROM "Mountain"
//      WHERE "Mountain"."height" BETWEEN 1000 AND 2000
//
// const mountains: string[]
```

### notBetween

```typescript
const mountains = await client.select({
   select: field(Moutain, 'name'),
   from: table(Mountain),
   where: notBetween(field(Mountain, 'height'), 1000, 2000),
});
// sql: SELECT "Mountain"."name"
//      FROM "Mountain"
//      WHERE "Mountain"."height" NOT BETWEEN 1000 AND 2000
//
// const mountains: string[]
```

### and

```typescript
const mountains = await client.select({
   select: {
     country: field(Moutain, 'country'),
     mountain: field(Moutain, 'name'),
   },
   from: table(Mountain),
   where: and(
     equal(field(Mountain, 'country'), 'CH'),
     greaterEqualThan(field(Mountain, 'height'), 2000),
   ),
});
// sql: SELECT "Mountain"."name", "Mountain"."country"
//      FROM "Mountain"
//      WHERE "Mountain"."country" = 'CH' AND "Mountain"."height" > 2000
//
// const mountains: { country: string, mountain: number }[]
```

### or

```typescript
const mountains = await client.select({
   select: {
     country: field(Moutain, 'country'),
     mountain: field(Moutain, 'name'),
   },
   from: table(Mountain),
   where: or(
     equal(field(Mountain, 'country'), 'CH'),
     greaterEqualThan(field(Mountain, 'height'), 2000),
   ),
});
// sql: SELECT "Mountain"."name", "Mountain"."country"
//      FROM "Mountain"
//      WHERE "Mountain"."country" = 'CH' OR "Mountain"."height" > 2000
//
// const mountains: { country: string, mountain: number }[]
```

## GROUP BY

```typescript
const names = await client.select({
   select: {
     country: field(Moutain, 'country'),
     count: count(),
   },
   from: table(Mountain),
   groupBy: field(Mountain, 'country'),
});
// sql: SELECT "Mountain"."country", count(*)
//      FROM "Mountain"
//      GROUP BY "Mountain"."country"
//
// const names: { country: string, count: number }[]
```

## HAVING BY

```typescript
const countries = await client.select({
   select: field(Moutain, 'country'),
   from: table(Mountain),
   groupBy: field(Mountain, 'country'),
   havingBy: greaterThan(count(*), 1),
});
// sql: SELECT "Mountain"."country"
//      FROM "Mountain"
//      GROUP BY "Mountain"."country"
//      HAVING BY count(*) > 1
//
// const countries: string[]
```

## ORDER BY

```typescript
const names = await client.select({
   select: field(Moutain, 'name'),
   from: table(Mountain),
   orderBy: field(Mountain, 'name')
});
// sql: SELECT "Mountain"."name"
//      FROM "Mountain"
//      ORDER BY "Mountain"."name"
//
// const names: string[]
```

```typescript
const names = await client.select({
   select: field(Moutain, 'name'),
   from: table(Mountain),
   orderBy: desc(field(Mountain, 'height'))
});
// sql: SELECT "Mountain"."name"
//      FROM "Mountain"
//      ORDER BY "Mountain"."height" DESC
//
// const names: string[]
```

```typescript
const names = await client.select({
   select: field(Moutain, 'name'),
   from: table(Mountain),
   orderBy: [
     desc(field(Mountain, 'height')),
     asc(field(Mountain, 'name')),
   ]
});
// sql: SELECT "Mountain"."name"
//      FROM "Mountain"
//      ORDER BY "Mountain"."height" DESC, "Mountain"."name" ASC
//
// const names: string[]
```

## LIMIT

```typescript
const names = await client.select({
   select: field(Moutain, 'name'),
   from: table(Mountain),
   limit: 5,
});
// sql: SELECT "Mountain"."name"
//      FROM "Mountain"
//      LIMIT 5
//
// const names: string[]
```

## OFFSET

```typescript
const names = await client.select({
   select: field(Moutain, 'name'),
   from: table(Mountain),
   offset: 5,
});
// sql: SELECT "Mountain"."name"
//      FROM "Mountain"
//      OFFSET 5
//
// const names: string[]
```


# INSERT

```typescript
const result = await client.insert({
   insert: {
       name: 'Matterhorn',
       height: 4478,
       country: 'CH',
   },
   into: table(Mountain),
});
// sql: INSERT INTO "Mountain" ("name", "height", "country") VALUES ('Matterhorn', 4478, 'CH')
//
// const result: { insertedRows: number }
```

```typescript
const result = await client.insert({
   insert: [{
       name: 'Matterhorn',
       height: 4478,
       country: 'CH',
   }, {
       name: 'Albis',
       height: 914.6,
       country: 'CH',
   }],
   into: table(Mountain),
});
// sql: INSERT INTO "Mountain" ("name", "height", "country") VALUES ('Matterhorn', 4478, 'CH'), ('Albis', 914.6, 'CH')
//
// const result: { insertedRows: number }
```

```typescript
const result = await client.insert({
   insert: {
       select: {
           name: field(Mountain, 'name'),
           height: field(Mountain, 'height'),
           country: 'IT',
       },
       from: table(Mountain),
       where: equal(field(Mountain, 'country'), 'CH'),
   },
   into: table(Mountain),
});
// sql: INSERT INTO "Mountain" ("name", "height", "country") 
//      SELECT "Mountain"."name", "Mountain"."height", 'IT'
//      WHERE "Mountain"."country" = 'CH'
//
// const result: { insertedRows: number }
```


# UPDATE

```typescript
const result = await client.update({
   update: table(Mountain),
   set: {
       height: 100,
   },
   where: equal(field(Mountain, 'country'), 'CH'),
});
// sql: UPDATE "Mountain" SET "height" = 100 WHERE "Mountain"."country" = 'CH'
//
// const result: { updatedRows: number }
```


# DELETE

```typescript
const result = await client.delete({
   delete: table(Mountain),
   where: equal(field(Mountain, 'country'), 'CH'),
});
// sql: DELETE FROM "Mountain" WHERE "Mountain"."country" = 'CH'
//
// const result: { deletedRows: number }
```


# Schema


# CREATE SCHEMA

```typescript
await client.exec({
   createSchema: 'Mountains',
   ifNotExists: true,
});

// sql: CREATE SCHEMA IF NOT EXISTS "Mountains"
```


# Table


# CREATE TABLE

```typescript
await client.exec({
   createTable: table('Mountains'),
   ifNotExists: true,
   columns: [{
       name: 'name',
       type: 'VARCHAR',
       notNull: true,
       primaryKey: true,
   }, {
       name: 'firstAscent',
       type: 'UUID',
   }],
   foreignKey: {
       firstAscent: {
           key: 'firstAscent',
           references: {
               table: table('Ascent'),
               primaryKey: ['id'],
           },
           onDelete: 'set null',
       }
   }
});

// sql: CREATE TABLE IF NOT EXISTS "Mountains" (
//         "name" VARCHAR NOT NULL,
//         "firstAscent" UUID
//      ), 
//      PRIMARY KEY ("name"),
//      CONSTRAINT "firstAscent" FOREIGN KEY ("firstAscent") REFERENCES "Ascent" ("id") ON DELETE set null
```


# ALTER TABLE

## RENAME TABLE

```typescript
await client.exec({
   alterTable: table(Mountain),
   renameTo: 'Mowntain',
});

// sql: ALTER TABLE "Mountain" RENAME TO "Mowntain"
```

## ADD COLUMN

```typescript
await client.exec({
   alterTable: table(Mountain),
   add: { column: 'country', type: 'VARCHAR' }
});

// sql: ALTER TABLE "Mountain" ADD COLUMN "country" VARCHAR
```

## DROP COLUMN

```typescript
await client.exec({
   alterTable: table(Mountain),
   drop: { column: 'country' }
});

// sql: ALTER TABLE "Mountain" DROP COLUMN "country"
```

## ADD PRIMARY KEY

```typescript
await client.exec({
   alterTable: table(Mountain),
   add: { primaryKey: 'name' }
});

// sql: ALTER TABLE "Mountain" ADD PRIMARY KEY ("name")
```

```typescript
await client.exec({
   alterTable: table(Mountain),
   add: { primaryKey: ['name', 'country'] }
});

// sql: ALTER TABLE "Mountain" ADD PRIMARY KEY ("name", "country")
```

## ADD FOREIGN KEY

```typescript
await client.exec({
   alterTable: table(Mountain),
   add: { 
      foreignKey: ['firstAscent'], 
      references: { 
         table: table(Ascent), 
         primaryKeys: ['id'] 
      }, 
      onDelete: 'cascade', 
      onUpdate: 'cascade',
   }
});

// sql: ALTER TABLE "Mountain" ADD FOREIGN KEY ("firstAscent") 
//      REFERENCES "Ascent" ("id") 
//      ON DELETE cascade ON UPDATE cascade
```

## DROP CONSTRAINT

```typescript
await client.exec({
   alterTable: table(Mountain),
   drop: { 
      constraint: 'Mountain_pkey'
   }
});

// sql: ALTER TABLE "Mountain" ADD FOREIGN KEY ("firstAscent") 
//      DROP CONSTRAINT "Mountain_pkey"
```


# DROP TABLE

```typescript
await client.exec({
   dropTable: table(Mountain),
   ifExists: true
});
// sql: DROP TABLE IF EXISTS "Mountain"
```


# LOCK TABLE

```typescript
await client.exec({
   lockTable: table(Mountain),
});
// sql: LOCK TALBE "Mountain"
```


# View


# CREATE VIEW

```typescript
await client.exec({
   createView: 'MountainsInSwitzerland',
   orReplace: true,
   as: {
       select: all(Mountain),
       from: table(Mountain),
       where: equal(field(Mountain, 'country'), 'CH'),
   }
});

// sql: CREATE OR REPLACE VIEW "MountainsInSwitzerland" AS
//      SELECT "Mountain".* FROM "Mountain"
//      WHERE "Mountain"."country" = 'CH'
```


# DROP VIEW

```typescript
await client.exec({
   dropView: table('MountainsInSwitzerland'),
   ifExists: true
});
// sql: DROP VIEW IF EXISTS "MountainsInSwitzerland"
```


# Index


# CREATE INDEX

```typescript
await client.exec({
   createIndex: 'MountainName',
   unique: true,
   on: table(Mountain),
   columns: ['name'],
});

// sql: CREATE UNIQUE INDEX "MountainName" ON "Mountain" ("name")
```


# DROP INDEX

```typescript
await client.exec({
   dropIndex: 'Mountain_pkey',
});
// sql: DROP INDEX "Mountain_pkey"
```


# Functions


# Aggregation


# AVG

```typescript
const stats = await client.select({
   select: {
       height: avg(Moutain, 'height'),
       country: field(Mountain, 'country'),
   }
   from: table(Mountain),
   groupBy: field(Mountain, 'country'),
});
// sql: SELECT avg("Mountain"."height"), "Mountain"."country"
//      FROM "Mountain"
//      GROUP BY "Mountain"."country"
//
// const stats: { height: number, country: string }[]
```


# COUNT

```typescript
const mountainCount = await client.selectFirst({
   select: count(),
   from: table(Mountain),
});
// sql: SELECT count(*)
//      FROM "Mountain"
//
// const mountainCount: number
```


# MAX

```typescript
const stats = await client.select({
   select: {
       height: max(Moutain, 'height'),
       country: field(Mountain, 'country'),
   }
   from: table(Mountain),
   groupBy: field(Mountain, 'country'),
});
// sql: SELECT sum("Mountain"."height"), "Mountain"."country"
//      FROM "Mountain"
//      GROUP BY "Mountain"."country"
//
// const stats: { height: number, country: string }[]
```


# MIN

```typescript
const stats = await client.select({
   select: {
       height: min(Moutain, 'height'),
       country: field(Mountain, 'country'),
   }
   from: table(Mountain),
   groupBy: field(Mountain, 'country'),
});
// sql: SELECT sum("Mountain"."height"), "Mountain"."country"
//      FROM "Mountain"
//      GROUP BY "Mountain"."country"
//
// const stats: { height: number, country: string }[]
```


# SUM

```typescript
const stats = await client.select({
   select: {
       height: sum(Moutain, 'height'),
       country: field(Mountain, 'country'),
   }
   from: table(Mountain),
   groupBy: field(Mountain, 'country'),
});
// sql: SELECT sum("Mountain"."height"), "Mountain"."country"
//      FROM "Mountain"
//      GROUP BY "Mountain"."country"
//
// const stats: { height: number, country: string }[]
```


# Conditional


# CASE WHEN

```typescript
const stats = await client.select({
   select: {
       height: caseWhen(case => case
          .when(greaterThan(field(Moutain, 'height'), 2000), 'Tier A')
          .when(greaterThan(field(Mountain, 'height'), 1000), 'Tier B')
          .else('Tier C'),
       name: field(Mountain, 'name'),
   }
   from: table(Mountain),
});
// sql: SELECT 
//         CASE WHEN "Mountain"."height" > 2000 THEN 'Tier A' 
//              WHEN "Mountain"."height" > 1000 THEN 'Tier B' 
//              ELSE 'Tier C' END, 
//         "Mountain"."name"
//      FROM "Mountain"
//
// const stats: { height: number, name: string }[]
```


# COALESCE

```typescript
const stats = await client.select({
   select: {
       height: coalesce([field(Moutain, 'height'), field(Moutain, 'backupHeight')]),
       name: field(Mountain, 'name'),
   }
   from: table(Mountain),
});
// sql: SELECT COALESCE("Mountain"."height", "Mountain"."backupHeight"), "Mountain"."name"
//      FROM "Mountain"
//
// const stats: { height: number, name: string }[]
```


# GREATEST


# LEAST


# Date


# DAY OF MONTH

```typescript
const mountains = await client.select({
   select: {
       name: field(Mountain, 'name'),
       day: dayOfMonth(field(Moutain, 'firstAscentDate')),
   },
   from: table(Mountain),
});
// postgres sql: SELECT "Mountain"."name", date_part('dow', "Mountain"."firstAscentDate")
//             FROM "Mountain"
//
// sqlite sql: SELECT "Mountain"."name", round(strftime('%d', "Mountain"."firstAscentDate"))
//             FROM "Mountain"
//
// const mountains: { name: string, day: number }[]
```


# DAY OF WEEK

```typescript
const mountains = await client.select({
   select: {
       name: field(Mountain, 'name'),
       day: dayOfWeek(field(Moutain, 'firstAscentDate')),
   },
   from: table(Mountain),
});
// postgres sql: SELECT "Mountain"."name", date_part('day', "Mountain"."firstAscentDate")
//             FROM "Mountain"
//
// sqlite sql: SELECT "Mountain"."name", round(strftime('%w', "Mountain"."firstAscentDate"))
//             FROM "Mountain"
//
// const mountains: { name: string, day: number }[]
```


# DAY OF YEAR

```typescript
const mountains = await client.select({
   select: {
       name: field(Mountain, 'name'),
       day: dayOfYear(field(Moutain, 'firstAscentDate')),
   },
   from: table(Mountain),
});
// postgres sql: SELECT "Mountain"."name", date_part('doy', "Mountain"."firstAscentDate")
//             FROM "Mountain"
//
// sqlite sql: SELECT "Mountain"."name", round(strftime('%j', "Mountain"."firstAscentDate"))
//             FROM "Mountain"
//
// const mountains: { name: string, day: number }[]
```


# HOUR

```typescript
const mountains = await client.select({
   select: {
       name: field(Mountain, 'name'),
       hour: hour(field(Moutain, 'firstAscentDate')),
   },
   from: table(Mountain),
});
// postgres sql: SELECT "Mountain"."name", date_part('hour', "Mountain"."firstAscentDate")
//             FROM "Mountain"
//
// sqlite sql: SELECT "Mountain"."name", round(strftime('%H', "Mountain"."firstAscentDate"))
//             FROM "Mountain"
//
// const mountains: { name: string, hour: number }[]
```


# MINUTE

```typescript
const mountains = await client.select({
   select: {
       name: field(Mountain, 'name'),
       minute: minute(field(Moutain, 'firstAscentDate')),
   },
   from: table(Mountain),
});
// postgres sql: SELECT "Mountain"."name", date_part('minute', "Mountain"."firstAscentDate")
//             FROM "Mountain"
//
// sqlite sql: SELECT "Mountain"."name", round(strftime('%M', "Mountain"."firstAscentDate"))
//             FROM "Mountain"
//
// const mountains: { name: string, minute: number }[]
```


# MONTH

```typescript
const mountains = await client.select({
   select: {
       name: field(Mountain, 'name'),
       month: month(field(Moutain, 'firstAscentDate')),
   },
   from: table(Mountain),
});
// postgres sql: SELECT "Mountain"."name", date_part('month', "Mountain"."firstAscentDate")
//             FROM "Mountain"
//
// sqlite sql: SELECT "Mountain"."name", round(strftime('%m', "Mountain"."firstAscentDate"))
//             FROM "Mountain"
//
// const mountains: { name: string, month: number }[]
```


# NOW


# SECOND


# WEEK OF YEAR

```typescript
const mountains = await client.select({
   select: {
       name: field(Mountain, 'name'),
       week: weekOfYear(field(Moutain, 'firstAscentDate')),
   },
   from: table(Mountain),
});
// postgres sql: SELECT "Mountain"."name", date_part('week', "Mountain"."firstAscentDate")
//             FROM "Mountain"
//
// sqlite sql: SELECT "Mountain"."name", round(strftime('%W', "Mountain"."firstAscentDate"))
//             FROM "Mountain"
//
// const mountains: { name: string, week: number }[]
```


# YEAR

```typescript
const mountains = await client.select({
   select: {
       name: field(Mountain, 'name'),
       year: year(field(Moutain, 'firstAscentDate')),
   },
   from: table(Mountain),
});
// postgres sql: SELECT "Mountain"."name", date_part('year', "Mountain"."firstAscentDate")
//             FROM "Mountain"
//
// sqlite sql: SELECT "Mountain"."name", round(strftime('%Y', "Mountain"."firstAscentDate"))
//             FROM "Mountain"
//
// const mountains: { name: string, year: number }[]
```


# Numeric


# CEIL

```typescript
const stats = await client.select({
   select: {
       height: ceil(Moutain, 'height'),
       name: field(Mountain, 'name'),
   }
   from: table(Mountain),
});
// sql: SELECT ceil("Mountain"."height"), "Mountain"."name"
//      FROM "Mountain"
//
// const stats: { height: number, name: string }[]
```


# FLOOR

```typescript
const stats = await client.select({
   select: {
       height: floor(Moutain, 'height'),
       name: field(Mountain, 'name'),
   }
   from: table(Mountain),
});
// sql: SELECT floor("Mountain"."height"), "Mountain"."name"
//      FROM "Mountain"
//
// const stats: { height: number, name: string }[]
```


# ROUND


# String


# CONCAT

```typescript
const names = await client.select({
   select: concat(field(Moutain, 'country'), ' ', field(Moutain, 'name')),
   from: table(Mountain),
});
// sql: SELECT "Mountain"."country" || ' ' || "Mountain"."name"
//      FROM "Mountain"
//
// const names: string[]
```


# ORM


# cli


# Adapters


# pg-adapter


# sqlite-adpater


# mariadb-adpater


# http-adpater


