2017-12-09 10 views
2

SQL의 열과 비슷한 필드 이름을 지정하는 방법이 있습니까? 이름 - - 전화 - 이메일 - 일부 필드가 가끔있을 수있는Tarantool - 명명 된 필드?

웹 사이트, 다른하지, 그들은 제시 될 수 있습니다

아이디어는 내가 가진 고객 레코드를 삽입 할 수 있다는 것입니다 다른 순서.

필드 이름으로 참조하는 튜플에 레코드를 삽입하는 다른 방법이 있습니까? 같은 의사의

뭔가 :

s:insert(1, "name": "foo name", "phone": "foo phone") 
s:insert(2, "phone": "bar phone", "name": "bar name", "email": "bar email") 
+0

avro 스키마를 사용하여 공간에 대한 스키마를 정의 할 수 있습니다. 여기에 아주 좋은 안내서가 있습니다 : https://tarantool.org/en/doc/1.7/book/app_server/creating_app.html. –

+0

감사합니다. 저는 현재 Marshmallow를 사용하고 있습니다 (아브로와 유사하다는 것을 알고있는 한). SQL 열의 이름과 동일한 필드에 이름을 지정하는 것이 있는지 궁금합니다. –

답변

2

당신이 공간에 대한 스키마를 정의 할 때 나중에, 아직 문서화되지 space:format() 기능을 사용하여 필드 이름을 지정할 수 있으며,이 인덱스 정의에 대한 이러한 이름을 사용할 수 있습니다. [available in Tarantool 1.7+]

샘플 코드 :

box.once("testapp:schema:1", function() 
    local customer = box.schema.space.create('customer') 
    customer:format({ 
     {'customer_id', 'unsigned'}, 
     {'name', 'string'}, 
    }) 
    customer:create_index('customer_id', {parts = {'customer_id'}}) 

    local account = box.schema.space.create('account') 
    account:format({ 
     {'account_id', 'unsigned'}, 
     {'customer_id', 'unsigned'}, 
     {'balance', 'unsigned'}, 
     {'name', 'string'}, 
    }) 
    account:create_index('account_id', {parts = {'account_id'}}) 
    account:create_index('customer_id', {parts = {'customer_id'}, unique = false}) 
    box.snapshot() 
end) 

불행하게도, 당신은 space:insert() 또는 유사한 기능에 필드 이름을 사용할 수 없습니다.