컨텐츠로 건너뛰기

Table

Table은 레코드 ID의 테이블 이름을 나타내는 클래스입니다.

import

import { Table } from "@tai-kun/surrealdb/decodeonly-datatypes";
import { Table } from "@tai-kun/surrealdb/encodable-datatypes";
import { Table } from "@tai-kun/surrealdb/standard-datatypes";

.constructor()

새로운 Table 객체를 생성합니다.

new Table(source: string); // decode-only, encodable
new Table(source: string | { name: string }); // standard

인수

source

테이블 이름 또는 Table 객체입니다. 프리셋이 standard 미만이라면 테이블 이름만 전달할 수 있습니다.

반환값

new를 통해 호출된 경우, Table은 해당 인스턴스를 반환합니다.

.name 인스턴스 속성 >=decode-only

테이블 이름입니다. 이 속성을 가져올 때 문자열은 이스케이프되지 않습니다.

.name: string;

예제

이 속성을 가져올 때 문자열은 이스케이프되지 않습니다.

import { Table } from "@tai-kun/surrealdb/decodeonly-datatypes";
const table = new Table("foo-bar");
console.log(table.name);
//-> foo-bar

.toString() 인스턴스 메서드 >=encodable

Table 객체를 SurrealQL 변수에서 사용 가능한 문자열로 변환합니다.

.valueOf().toJSON()은 이 메서드와 동일한 결과를 반환합니다.

.toString(): string;

인수

없음.

반환값

테이블 이름을 반환합니다.

예제

import { Table } from "@tai-kun/surrealdb/encodable-datatypes";
const table = new Table("foo-bar");
console.log(table.toString());
//-> foo-bar

.toSurql() 인스턴스 메서드 >=encodable

Table 객체를 SurrealQL에 포함할 수 있는 문자열로 변환합니다. .toString()과 유사하지만, 테이블 이름은 SurrealDB 구현과 동일하게 이스케이프됩니다.

.toSurql(): string;

인수

없음.

반환값

이스케이프된 테이블 이름 문자열을 반환합니다.

예제

import { Table } from "@tai-kun/surrealdb/encodable-datatypes";
const table = new Table("foo-bar");
console.log(table.toSurql());
//-> `foo-bar`

.clone() 인스턴스 메서드 =standard

Table 객체를 복제합니다.

.clone(): this;

인수

없음.

반환값

새로운 Table 객체를 반환합니다. Table 클래스를 상속하는 경우 해당 클래스의 인스턴스가 반환됩니다.

심화

타입 가드

Table의 테이블 이름을 타입 매개변수를 사용하여 타입 안전하게 만들 수 있습니다:

import { Table } from "@tai-kun/surrealdb/standard-datatypes";
function isUserTable(table: unknown): table is Table<"user"> {
return table instanceof Table
&& table.name === "user"
}

Table 객체의 일반적인 판정

프리셋에 의존하지 않고 값이 Table 객체인지 판정하려면 isTable 함수를 사용하는 것을 권장합니다. 이 함수는 instanceof를 사용하지 않으므로, 검증할 값의 프리셋이 불명확한 경우에 유용합니다.

import { isTable } from "@tai-kun/surrealdb";