라이브러리

[PHP] SwooleTable::create - Swoole 메모리 테이블을 만듭니다.




SwooleTable::create

SwooleTable은 Swoole의 고성능 데이터베이스입니다. SwooleTable::create는 SwooleTable을 생성하는 메서드입니다. 이 메서드는 테이블 이름, 필드 이름, 필드 타입을 지정하여 테이블을 생성합니다.

예제


#hostingforum.kr
php

use SwooleTable;



// 테이블 이름을 지정합니다.

$tableName = 'users';



// 테이블을 생성합니다.

$table = Table::create($tableName);



// 테이블에 필드를 추가합니다.

$table->column('id', Table::TYPE_INT, 11);

$table->column('name', Table::TYPE_STRING, 255);

$table->column('email', Table::TYPE_STRING, 255);



// 테이블을 초기화합니다.

$table->create();



// 테이블에 데이터를 삽입합니다.

$table->set('1', ['id' => 1, 'name' => 'John Doe', 'email' => 'john@example.com']);

$table->set('2', ['id' => 2, 'name' => 'Jane Doe', 'email' => 'jane@example.com']);



// 테이블에서 데이터를 조회합니다.

$data = $table->get('1');

print_r($data);



// 테이블에서 데이터를 삭제합니다.

$table->delete('1');



// 테이블을 삭제합니다.

$table->destroy();



필드 타입


SwooleTable에서 지원하는 필드 타입은 다음과 같습니다.

* `Table::TYPE_INT`: 32비트 정수
* `Table::TYPE_STRING`: 문자열
* `Table::TYPE_FLOAT`: 64비트 실수
* `Table::TYPE_BOOL`: 불리언
* `Table::TYPE_ARRAY`: 배열
* `Table::TYPE_OBJECT`: 객체

필드 옵션


SwooleTable에서 필드 옵션을 지정할 수 있습니다.

* `Table::OPTION_NULLABLE`: 필드가 null이 될 수 있는지 여부
* `Table::OPTION_DEFAULT`: 필드의 기본값
* `Table::OPTION_AUTO_INCREMENT`: 필드가 자동으로 증가하는지 여부

예제 (필드 옵션)


#hostingforum.kr
php

use SwooleTable;



$tableName = 'users';



$table = Table::create($tableName);



$table->column('id', Table::TYPE_INT, 11, Table::OPTION_AUTO_INCREMENT);

$table->column('name', Table::TYPE_STRING, 255, Table::OPTION_NULLABLE);

$table->column('email', Table::TYPE_STRING, 255, ['default' => 'example@example.com']);



$table->create();



$table->set('1', ['id' => 1, 'name' => 'John Doe', 'email' => 'john@example.com']);

$table->set('2', ['id' => 2, 'name' => 'Jane Doe', 'email' => 'jane@example.com']);



$data = $table->get('1');

print_r($data);



참고


SwooleTable은 고성능 데이터베이스이므로, 데이터를 삽입, 삭제, 조회할 때 주의해야 합니다. 또한, 필드 타입과 옵션을 지정할 때 주의해야 합니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 8,985건 / 94 페이지

검색

게시물 검색