改进
This commit is contained in:
parent
6d98dd7317
commit
abf9952212
@ -29,7 +29,7 @@ type CreateDocumentRequest struct {
|
|||||||
|
|
||||||
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
|
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
|
||||||
Content string `protobuf:"bytes,2,opt,name=content,proto3" json:"content,omitempty"`
|
Content string `protobuf:"bytes,2,opt,name=content,proto3" json:"content,omitempty"`
|
||||||
LibraryId string `protobuf:"bytes,3,opt,name=library_id,json=libraryId,proto3" json:"library_id,omitempty"`
|
LibraryId int64 `protobuf:"varint,3,opt,name=library_id,json=libraryId,proto3" json:"library_id,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *CreateDocumentRequest) Reset() {
|
func (x *CreateDocumentRequest) Reset() {
|
||||||
@ -78,11 +78,11 @@ func (x *CreateDocumentRequest) GetContent() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *CreateDocumentRequest) GetLibraryId() string {
|
func (x *CreateDocumentRequest) GetLibraryId() int64 {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.LibraryId
|
return x.LibraryId
|
||||||
}
|
}
|
||||||
return ""
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateDocumentResponse struct {
|
type CreateDocumentResponse struct {
|
||||||
@ -137,7 +137,7 @@ type ListDocumentRequest struct {
|
|||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
LibraryId string `protobuf:"bytes,1,opt,name=library_id,json=libraryId,proto3" json:"library_id,omitempty"`
|
LibraryId int64 `protobuf:"varint,1,opt,name=library_id,json=libraryId,proto3" json:"library_id,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *ListDocumentRequest) Reset() {
|
func (x *ListDocumentRequest) Reset() {
|
||||||
@ -172,11 +172,11 @@ func (*ListDocumentRequest) Descriptor() ([]byte, []int) {
|
|||||||
return file_api_rag_document_proto_rawDescGZIP(), []int{2}
|
return file_api_rag_document_proto_rawDescGZIP(), []int{2}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *ListDocumentRequest) GetLibraryId() string {
|
func (x *ListDocumentRequest) GetLibraryId() int64 {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.LibraryId
|
return x.LibraryId
|
||||||
}
|
}
|
||||||
return ""
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListDocumentResponse struct {
|
type ListDocumentResponse struct {
|
||||||
@ -234,7 +234,7 @@ type Document struct {
|
|||||||
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
|
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||||
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
|
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
|
||||||
Content string `protobuf:"bytes,3,opt,name=content,proto3" json:"content,omitempty"`
|
Content string `protobuf:"bytes,3,opt,name=content,proto3" json:"content,omitempty"`
|
||||||
LibraryId string `protobuf:"bytes,4,opt,name=library_id,json=libraryId,proto3" json:"library_id,omitempty"`
|
LibraryId int64 `protobuf:"varint,4,opt,name=library_id,json=libraryId,proto3" json:"library_id,omitempty"`
|
||||||
UserId string `protobuf:"bytes,5,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"`
|
UserId string `protobuf:"bytes,5,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"`
|
||||||
CreatedAt string `protobuf:"bytes,6,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"`
|
CreatedAt string `protobuf:"bytes,6,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"`
|
||||||
UpdatedAt string `protobuf:"bytes,7,opt,name=updated_at,json=updatedAt,proto3" json:"updated_at,omitempty"`
|
UpdatedAt string `protobuf:"bytes,7,opt,name=updated_at,json=updatedAt,proto3" json:"updated_at,omitempty"`
|
||||||
@ -293,11 +293,11 @@ func (x *Document) GetContent() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *Document) GetLibraryId() string {
|
func (x *Document) GetLibraryId() int64 {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.LibraryId
|
return x.LibraryId
|
||||||
}
|
}
|
||||||
return ""
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *Document) GetUserId() string {
|
func (x *Document) GetUserId() string {
|
||||||
@ -334,7 +334,7 @@ var file_api_rag_document_proto_rawDesc = []byte{
|
|||||||
0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x18,
|
0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x18,
|
||||||
0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
|
0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||||
0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x6c, 0x69, 0x62, 0x72,
|
0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x6c, 0x69, 0x62, 0x72,
|
||||||
0x61, 0x72, 0x79, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x6c, 0x69,
|
0x61, 0x72, 0x79, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x6c, 0x69,
|
||||||
0x62, 0x72, 0x61, 0x72, 0x79, 0x49, 0x64, 0x22, 0x3f, 0x0a, 0x16, 0x43, 0x72, 0x65, 0x61, 0x74,
|
0x62, 0x72, 0x61, 0x72, 0x79, 0x49, 0x64, 0x22, 0x3f, 0x0a, 0x16, 0x43, 0x72, 0x65, 0x61, 0x74,
|
||||||
0x65, 0x44, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
|
0x65, 0x44, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
|
||||||
0x65, 0x12, 0x25, 0x0a, 0x08, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x01, 0x20,
|
0x65, 0x12, 0x25, 0x0a, 0x08, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x01, 0x20,
|
||||||
@ -342,7 +342,7 @@ var file_api_rag_document_proto_rawDesc = []byte{
|
|||||||
0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x22, 0x34, 0x0a, 0x13, 0x4c, 0x69, 0x73, 0x74,
|
0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x22, 0x34, 0x0a, 0x13, 0x4c, 0x69, 0x73, 0x74,
|
||||||
0x44, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12,
|
0x44, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12,
|
||||||
0x1d, 0x0a, 0x0a, 0x6c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20,
|
0x1d, 0x0a, 0x0a, 0x6c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20,
|
||||||
0x01, 0x28, 0x09, 0x52, 0x09, 0x6c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x49, 0x64, 0x22, 0x3f,
|
0x01, 0x28, 0x03, 0x52, 0x09, 0x6c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x49, 0x64, 0x22, 0x3f,
|
||||||
0x0a, 0x14, 0x4c, 0x69, 0x73, 0x74, 0x44, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65,
|
0x0a, 0x14, 0x4c, 0x69, 0x73, 0x74, 0x44, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65,
|
||||||
0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x27, 0x0a, 0x09, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65,
|
0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x27, 0x0a, 0x09, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65,
|
||||||
0x6e, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x44, 0x6f, 0x63, 0x75,
|
0x6e, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x44, 0x6f, 0x63, 0x75,
|
||||||
@ -352,7 +352,7 @@ var file_api_rag_document_proto_rawDesc = []byte{
|
|||||||
0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65,
|
0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65,
|
||||||
0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28,
|
0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28,
|
||||||
0x09, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x6c, 0x69,
|
0x09, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x6c, 0x69,
|
||||||
0x62, 0x72, 0x61, 0x72, 0x79, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09,
|
0x62, 0x72, 0x61, 0x72, 0x79, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09,
|
||||||
0x6c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x49, 0x64, 0x12, 0x17, 0x0a, 0x07, 0x75, 0x73, 0x65,
|
0x6c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x49, 0x64, 0x12, 0x17, 0x0a, 0x07, 0x75, 0x73, 0x65,
|
||||||
0x72, 0x5f, 0x69, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72,
|
0x72, 0x5f, 0x69, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72,
|
||||||
0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74,
|
0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74,
|
||||||
|
@ -9,7 +9,7 @@ option go_package = "leafdev.top/leaf/rag/api/rag";
|
|||||||
message CreateDocumentRequest {
|
message CreateDocumentRequest {
|
||||||
string name = 1;
|
string name = 1;
|
||||||
string content = 2;
|
string content = 2;
|
||||||
string library_id = 3;
|
int64 library_id = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message CreateDocumentResponse {
|
message CreateDocumentResponse {
|
||||||
@ -17,19 +17,32 @@ message CreateDocumentResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message ListDocumentRequest {
|
message ListDocumentRequest {
|
||||||
string library_id = 1;
|
int64 library_id = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ListDocumentResponse {
|
message ListDocumentResponse {
|
||||||
repeated Document documents = 1;
|
repeated Document documents = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message CreateDocumentBlockRequest {
|
||||||
|
int64 document_id = 1;
|
||||||
|
string content = 2;
|
||||||
|
}
|
||||||
|
|
||||||
message Document {
|
message Document {
|
||||||
int64 id = 1;
|
int64 id = 1;
|
||||||
string name = 2;
|
string name = 2;
|
||||||
string content = 3;
|
string content = 3;
|
||||||
string library_id = 4;
|
int64 library_id = 4;
|
||||||
string user_id = 5;
|
string user_id = 5;
|
||||||
string created_at = 6;
|
string created_at = 6;
|
||||||
string updated_at = 7;
|
string updated_at = 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DocumentBlock {
|
||||||
|
int64 id = 1;
|
||||||
|
string content = 2;
|
||||||
|
int64 document_id = 3;
|
||||||
|
string created_at = 4;
|
||||||
|
string updated_at = 5;
|
||||||
}
|
}
|
@ -38,7 +38,8 @@
|
|||||||
"name": "libraryId",
|
"name": "libraryId",
|
||||||
"in": "query",
|
"in": "query",
|
||||||
"required": false,
|
"required": false,
|
||||||
"type": "string"
|
"type": "string",
|
||||||
|
"format": "int64"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
@ -79,7 +80,8 @@
|
|||||||
"name": "libraryId",
|
"name": "libraryId",
|
||||||
"in": "query",
|
"in": "query",
|
||||||
"required": false,
|
"required": false,
|
||||||
"type": "string"
|
"type": "string",
|
||||||
|
"format": "int64"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
@ -178,7 +180,8 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"libraryId": {
|
"libraryId": {
|
||||||
"type": "string"
|
"type": "string",
|
||||||
|
"format": "int64"
|
||||||
},
|
},
|
||||||
"userId": {
|
"userId": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
@ -24,7 +24,7 @@ const _ = grpc.SupportPackageIsVersion7
|
|||||||
type RAGServiceClient interface {
|
type RAGServiceClient interface {
|
||||||
ListLibrary(ctx context.Context, in *ListLibraryRequest, opts ...grpc.CallOption) (*ListLibraryResponse, error)
|
ListLibrary(ctx context.Context, in *ListLibraryRequest, opts ...grpc.CallOption) (*ListLibraryResponse, error)
|
||||||
CreateLibrary(ctx context.Context, in *CreateLibraryRequest, opts ...grpc.CallOption) (*CreateLibraryResponse, error)
|
CreateLibrary(ctx context.Context, in *CreateLibraryRequest, opts ...grpc.CallOption) (*CreateLibraryResponse, error)
|
||||||
// DocumentService
|
// DocumentService
|
||||||
CreateDocument(ctx context.Context, in *CreateDocumentRequest, opts ...grpc.CallOption) (*CreateDocumentResponse, error)
|
CreateDocument(ctx context.Context, in *CreateDocumentRequest, opts ...grpc.CallOption) (*CreateDocumentResponse, error)
|
||||||
ListDocument(ctx context.Context, in *ListDocumentRequest, opts ...grpc.CallOption) (*ListDocumentResponse, error)
|
ListDocument(ctx context.Context, in *ListDocumentRequest, opts ...grpc.CallOption) (*ListDocumentResponse, error)
|
||||||
}
|
}
|
||||||
@ -79,7 +79,7 @@ func (c *rAGServiceClient) ListDocument(ctx context.Context, in *ListDocumentReq
|
|||||||
type RAGServiceServer interface {
|
type RAGServiceServer interface {
|
||||||
ListLibrary(context.Context, *ListLibraryRequest) (*ListLibraryResponse, error)
|
ListLibrary(context.Context, *ListLibraryRequest) (*ListLibraryResponse, error)
|
||||||
CreateLibrary(context.Context, *CreateLibraryRequest) (*CreateLibraryResponse, error)
|
CreateLibrary(context.Context, *CreateLibraryRequest) (*CreateLibraryResponse, error)
|
||||||
// DocumentService
|
// DocumentService
|
||||||
CreateDocument(context.Context, *CreateDocumentRequest) (*CreateDocumentResponse, error)
|
CreateDocument(context.Context, *CreateDocumentRequest) (*CreateDocumentResponse, error)
|
||||||
ListDocument(context.Context, *ListDocumentRequest) (*ListDocumentResponse, error)
|
ListDocument(context.Context, *ListDocumentRequest) (*ListDocumentResponse, error)
|
||||||
mustEmbedUnimplementedRAGServiceServer()
|
mustEmbedUnimplementedRAGServiceServer()
|
||||||
|
@ -21,6 +21,8 @@ type Document struct {
|
|||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
// UserID holds the value of the "user_id" field.
|
// UserID holds the value of the "user_id" field.
|
||||||
UserID string `json:"user_id,omitempty"`
|
UserID string `json:"user_id,omitempty"`
|
||||||
|
// LibraryID holds the value of the "library_id" field.
|
||||||
|
LibraryID int64 `json:"library_id,omitempty"`
|
||||||
// CreatedAt holds the value of the "created_at" field.
|
// CreatedAt holds the value of the "created_at" field.
|
||||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||||
// UpdatedAt holds the value of the "updated_at" field.
|
// UpdatedAt holds the value of the "updated_at" field.
|
||||||
@ -34,7 +36,7 @@ func (*Document) scanValues(columns []string) ([]any, error) {
|
|||||||
values := make([]any, len(columns))
|
values := make([]any, len(columns))
|
||||||
for i := range columns {
|
for i := range columns {
|
||||||
switch columns[i] {
|
switch columns[i] {
|
||||||
case document.FieldID:
|
case document.FieldID, document.FieldLibraryID:
|
||||||
values[i] = new(sql.NullInt64)
|
values[i] = new(sql.NullInt64)
|
||||||
case document.FieldName, document.FieldUserID:
|
case document.FieldName, document.FieldUserID:
|
||||||
values[i] = new(sql.NullString)
|
values[i] = new(sql.NullString)
|
||||||
@ -75,6 +77,12 @@ func (d *Document) assignValues(columns []string, values []any) error {
|
|||||||
} else if value.Valid {
|
} else if value.Valid {
|
||||||
d.UserID = value.String
|
d.UserID = value.String
|
||||||
}
|
}
|
||||||
|
case document.FieldLibraryID:
|
||||||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field library_id", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
d.LibraryID = value.Int64
|
||||||
|
}
|
||||||
case document.FieldCreatedAt:
|
case document.FieldCreatedAt:
|
||||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
return fmt.Errorf("unexpected type %T for field created_at", values[i])
|
return fmt.Errorf("unexpected type %T for field created_at", values[i])
|
||||||
@ -136,6 +144,9 @@ func (d *Document) String() string {
|
|||||||
builder.WriteString("user_id=")
|
builder.WriteString("user_id=")
|
||||||
builder.WriteString(d.UserID)
|
builder.WriteString(d.UserID)
|
||||||
builder.WriteString(", ")
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("library_id=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", d.LibraryID))
|
||||||
|
builder.WriteString(", ")
|
||||||
builder.WriteString("created_at=")
|
builder.WriteString("created_at=")
|
||||||
builder.WriteString(d.CreatedAt.Format(time.ANSIC))
|
builder.WriteString(d.CreatedAt.Format(time.ANSIC))
|
||||||
builder.WriteString(", ")
|
builder.WriteString(", ")
|
||||||
|
@ -17,6 +17,8 @@ const (
|
|||||||
FieldName = "name"
|
FieldName = "name"
|
||||||
// FieldUserID holds the string denoting the user_id field in the database.
|
// FieldUserID holds the string denoting the user_id field in the database.
|
||||||
FieldUserID = "user_id"
|
FieldUserID = "user_id"
|
||||||
|
// FieldLibraryID holds the string denoting the library_id field in the database.
|
||||||
|
FieldLibraryID = "library_id"
|
||||||
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||||
FieldCreatedAt = "created_at"
|
FieldCreatedAt = "created_at"
|
||||||
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||||
@ -30,6 +32,7 @@ var Columns = []string{
|
|||||||
FieldID,
|
FieldID,
|
||||||
FieldName,
|
FieldName,
|
||||||
FieldUserID,
|
FieldUserID,
|
||||||
|
FieldLibraryID,
|
||||||
FieldCreatedAt,
|
FieldCreatedAt,
|
||||||
FieldUpdatedAt,
|
FieldUpdatedAt,
|
||||||
}
|
}
|
||||||
@ -80,6 +83,11 @@ func ByUserID(opts ...sql.OrderTermOption) OrderOption {
|
|||||||
return sql.OrderByField(FieldUserID, opts...).ToFunc()
|
return sql.OrderByField(FieldUserID, opts...).ToFunc()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ByLibraryID orders the results by the library_id field.
|
||||||
|
func ByLibraryID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldLibraryID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
// ByCreatedAt orders the results by the created_at field.
|
// ByCreatedAt orders the results by the created_at field.
|
||||||
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||||
|
@ -64,6 +64,11 @@ func UserID(v string) predicate.Document {
|
|||||||
return predicate.Document(sql.FieldEQ(FieldUserID, v))
|
return predicate.Document(sql.FieldEQ(FieldUserID, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LibraryID applies equality check predicate on the "library_id" field. It's identical to LibraryIDEQ.
|
||||||
|
func LibraryID(v int64) predicate.Document {
|
||||||
|
return predicate.Document(sql.FieldEQ(FieldLibraryID, v))
|
||||||
|
}
|
||||||
|
|
||||||
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||||
func CreatedAt(v time.Time) predicate.Document {
|
func CreatedAt(v time.Time) predicate.Document {
|
||||||
return predicate.Document(sql.FieldEQ(FieldCreatedAt, v))
|
return predicate.Document(sql.FieldEQ(FieldCreatedAt, v))
|
||||||
@ -204,6 +209,46 @@ func UserIDContainsFold(v string) predicate.Document {
|
|||||||
return predicate.Document(sql.FieldContainsFold(FieldUserID, v))
|
return predicate.Document(sql.FieldContainsFold(FieldUserID, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LibraryIDEQ applies the EQ predicate on the "library_id" field.
|
||||||
|
func LibraryIDEQ(v int64) predicate.Document {
|
||||||
|
return predicate.Document(sql.FieldEQ(FieldLibraryID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LibraryIDNEQ applies the NEQ predicate on the "library_id" field.
|
||||||
|
func LibraryIDNEQ(v int64) predicate.Document {
|
||||||
|
return predicate.Document(sql.FieldNEQ(FieldLibraryID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LibraryIDIn applies the In predicate on the "library_id" field.
|
||||||
|
func LibraryIDIn(vs ...int64) predicate.Document {
|
||||||
|
return predicate.Document(sql.FieldIn(FieldLibraryID, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LibraryIDNotIn applies the NotIn predicate on the "library_id" field.
|
||||||
|
func LibraryIDNotIn(vs ...int64) predicate.Document {
|
||||||
|
return predicate.Document(sql.FieldNotIn(FieldLibraryID, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LibraryIDGT applies the GT predicate on the "library_id" field.
|
||||||
|
func LibraryIDGT(v int64) predicate.Document {
|
||||||
|
return predicate.Document(sql.FieldGT(FieldLibraryID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LibraryIDGTE applies the GTE predicate on the "library_id" field.
|
||||||
|
func LibraryIDGTE(v int64) predicate.Document {
|
||||||
|
return predicate.Document(sql.FieldGTE(FieldLibraryID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LibraryIDLT applies the LT predicate on the "library_id" field.
|
||||||
|
func LibraryIDLT(v int64) predicate.Document {
|
||||||
|
return predicate.Document(sql.FieldLT(FieldLibraryID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// LibraryIDLTE applies the LTE predicate on the "library_id" field.
|
||||||
|
func LibraryIDLTE(v int64) predicate.Document {
|
||||||
|
return predicate.Document(sql.FieldLTE(FieldLibraryID, v))
|
||||||
|
}
|
||||||
|
|
||||||
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||||
func CreatedAtEQ(v time.Time) predicate.Document {
|
func CreatedAtEQ(v time.Time) predicate.Document {
|
||||||
return predicate.Document(sql.FieldEQ(FieldCreatedAt, v))
|
return predicate.Document(sql.FieldEQ(FieldCreatedAt, v))
|
||||||
|
@ -32,6 +32,12 @@ func (dc *DocumentCreate) SetUserID(s string) *DocumentCreate {
|
|||||||
return dc
|
return dc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetLibraryID sets the "library_id" field.
|
||||||
|
func (dc *DocumentCreate) SetLibraryID(i int64) *DocumentCreate {
|
||||||
|
dc.mutation.SetLibraryID(i)
|
||||||
|
return dc
|
||||||
|
}
|
||||||
|
|
||||||
// SetCreatedAt sets the "created_at" field.
|
// SetCreatedAt sets the "created_at" field.
|
||||||
func (dc *DocumentCreate) SetCreatedAt(t time.Time) *DocumentCreate {
|
func (dc *DocumentCreate) SetCreatedAt(t time.Time) *DocumentCreate {
|
||||||
dc.mutation.SetCreatedAt(t)
|
dc.mutation.SetCreatedAt(t)
|
||||||
@ -113,6 +119,9 @@ func (dc *DocumentCreate) check() error {
|
|||||||
if _, ok := dc.mutation.UserID(); !ok {
|
if _, ok := dc.mutation.UserID(); !ok {
|
||||||
return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "Document.user_id"`)}
|
return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "Document.user_id"`)}
|
||||||
}
|
}
|
||||||
|
if _, ok := dc.mutation.LibraryID(); !ok {
|
||||||
|
return &ValidationError{Name: "library_id", err: errors.New(`ent: missing required field "Document.library_id"`)}
|
||||||
|
}
|
||||||
if _, ok := dc.mutation.CreatedAt(); !ok {
|
if _, ok := dc.mutation.CreatedAt(); !ok {
|
||||||
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Document.created_at"`)}
|
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Document.created_at"`)}
|
||||||
}
|
}
|
||||||
@ -153,6 +162,10 @@ func (dc *DocumentCreate) createSpec() (*Document, *sqlgraph.CreateSpec) {
|
|||||||
_spec.SetField(document.FieldUserID, field.TypeString, value)
|
_spec.SetField(document.FieldUserID, field.TypeString, value)
|
||||||
_node.UserID = value
|
_node.UserID = value
|
||||||
}
|
}
|
||||||
|
if value, ok := dc.mutation.LibraryID(); ok {
|
||||||
|
_spec.SetField(document.FieldLibraryID, field.TypeInt64, value)
|
||||||
|
_node.LibraryID = value
|
||||||
|
}
|
||||||
if value, ok := dc.mutation.CreatedAt(); ok {
|
if value, ok := dc.mutation.CreatedAt(); ok {
|
||||||
_spec.SetField(document.FieldCreatedAt, field.TypeTime, value)
|
_spec.SetField(document.FieldCreatedAt, field.TypeTime, value)
|
||||||
_node.CreatedAt = value
|
_node.CreatedAt = value
|
||||||
|
@ -56,6 +56,27 @@ func (du *DocumentUpdate) SetNillableUserID(s *string) *DocumentUpdate {
|
|||||||
return du
|
return du
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetLibraryID sets the "library_id" field.
|
||||||
|
func (du *DocumentUpdate) SetLibraryID(i int64) *DocumentUpdate {
|
||||||
|
du.mutation.ResetLibraryID()
|
||||||
|
du.mutation.SetLibraryID(i)
|
||||||
|
return du
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableLibraryID sets the "library_id" field if the given value is not nil.
|
||||||
|
func (du *DocumentUpdate) SetNillableLibraryID(i *int64) *DocumentUpdate {
|
||||||
|
if i != nil {
|
||||||
|
du.SetLibraryID(*i)
|
||||||
|
}
|
||||||
|
return du
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddLibraryID adds i to the "library_id" field.
|
||||||
|
func (du *DocumentUpdate) AddLibraryID(i int64) *DocumentUpdate {
|
||||||
|
du.mutation.AddLibraryID(i)
|
||||||
|
return du
|
||||||
|
}
|
||||||
|
|
||||||
// SetCreatedAt sets the "created_at" field.
|
// SetCreatedAt sets the "created_at" field.
|
||||||
func (du *DocumentUpdate) SetCreatedAt(t time.Time) *DocumentUpdate {
|
func (du *DocumentUpdate) SetCreatedAt(t time.Time) *DocumentUpdate {
|
||||||
du.mutation.SetCreatedAt(t)
|
du.mutation.SetCreatedAt(t)
|
||||||
@ -131,6 +152,12 @@ func (du *DocumentUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|||||||
if value, ok := du.mutation.UserID(); ok {
|
if value, ok := du.mutation.UserID(); ok {
|
||||||
_spec.SetField(document.FieldUserID, field.TypeString, value)
|
_spec.SetField(document.FieldUserID, field.TypeString, value)
|
||||||
}
|
}
|
||||||
|
if value, ok := du.mutation.LibraryID(); ok {
|
||||||
|
_spec.SetField(document.FieldLibraryID, field.TypeInt64, value)
|
||||||
|
}
|
||||||
|
if value, ok := du.mutation.AddedLibraryID(); ok {
|
||||||
|
_spec.AddField(document.FieldLibraryID, field.TypeInt64, value)
|
||||||
|
}
|
||||||
if value, ok := du.mutation.CreatedAt(); ok {
|
if value, ok := du.mutation.CreatedAt(); ok {
|
||||||
_spec.SetField(document.FieldCreatedAt, field.TypeTime, value)
|
_spec.SetField(document.FieldCreatedAt, field.TypeTime, value)
|
||||||
}
|
}
|
||||||
@ -185,6 +212,27 @@ func (duo *DocumentUpdateOne) SetNillableUserID(s *string) *DocumentUpdateOne {
|
|||||||
return duo
|
return duo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetLibraryID sets the "library_id" field.
|
||||||
|
func (duo *DocumentUpdateOne) SetLibraryID(i int64) *DocumentUpdateOne {
|
||||||
|
duo.mutation.ResetLibraryID()
|
||||||
|
duo.mutation.SetLibraryID(i)
|
||||||
|
return duo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableLibraryID sets the "library_id" field if the given value is not nil.
|
||||||
|
func (duo *DocumentUpdateOne) SetNillableLibraryID(i *int64) *DocumentUpdateOne {
|
||||||
|
if i != nil {
|
||||||
|
duo.SetLibraryID(*i)
|
||||||
|
}
|
||||||
|
return duo
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddLibraryID adds i to the "library_id" field.
|
||||||
|
func (duo *DocumentUpdateOne) AddLibraryID(i int64) *DocumentUpdateOne {
|
||||||
|
duo.mutation.AddLibraryID(i)
|
||||||
|
return duo
|
||||||
|
}
|
||||||
|
|
||||||
// SetCreatedAt sets the "created_at" field.
|
// SetCreatedAt sets the "created_at" field.
|
||||||
func (duo *DocumentUpdateOne) SetCreatedAt(t time.Time) *DocumentUpdateOne {
|
func (duo *DocumentUpdateOne) SetCreatedAt(t time.Time) *DocumentUpdateOne {
|
||||||
duo.mutation.SetCreatedAt(t)
|
duo.mutation.SetCreatedAt(t)
|
||||||
@ -290,6 +338,12 @@ func (duo *DocumentUpdateOne) sqlSave(ctx context.Context) (_node *Document, err
|
|||||||
if value, ok := duo.mutation.UserID(); ok {
|
if value, ok := duo.mutation.UserID(); ok {
|
||||||
_spec.SetField(document.FieldUserID, field.TypeString, value)
|
_spec.SetField(document.FieldUserID, field.TypeString, value)
|
||||||
}
|
}
|
||||||
|
if value, ok := duo.mutation.LibraryID(); ok {
|
||||||
|
_spec.SetField(document.FieldLibraryID, field.TypeInt64, value)
|
||||||
|
}
|
||||||
|
if value, ok := duo.mutation.AddedLibraryID(); ok {
|
||||||
|
_spec.AddField(document.FieldLibraryID, field.TypeInt64, value)
|
||||||
|
}
|
||||||
if value, ok := duo.mutation.CreatedAt(); ok {
|
if value, ok := duo.mutation.CreatedAt(); ok {
|
||||||
_spec.SetField(document.FieldCreatedAt, field.TypeTime, value)
|
_spec.SetField(document.FieldCreatedAt, field.TypeTime, value)
|
||||||
}
|
}
|
||||||
|
@ -22,9 +22,9 @@ type DocumentBlock struct {
|
|||||||
// Content holds the value of the "content" field.
|
// Content holds the value of the "content" field.
|
||||||
Content string `json:"content,omitempty"`
|
Content string `json:"content,omitempty"`
|
||||||
// Order holds the value of the "order" field.
|
// Order holds the value of the "order" field.
|
||||||
Order int `json:"order,omitempty"`
|
Order int64 `json:"order,omitempty"`
|
||||||
// DocumentID holds the value of the "document_id" field.
|
// DocumentID holds the value of the "document_id" field.
|
||||||
DocumentID int `json:"document_id,omitempty"`
|
DocumentID int64 `json:"document_id,omitempty"`
|
||||||
// UserID holds the value of the "user_id" field.
|
// UserID holds the value of the "user_id" field.
|
||||||
UserID string `json:"user_id,omitempty"`
|
UserID string `json:"user_id,omitempty"`
|
||||||
// CreatedAt holds the value of the "created_at" field.
|
// CreatedAt holds the value of the "created_at" field.
|
||||||
@ -103,13 +103,13 @@ func (db *DocumentBlock) assignValues(columns []string, values []any) error {
|
|||||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
return fmt.Errorf("unexpected type %T for field order", values[i])
|
return fmt.Errorf("unexpected type %T for field order", values[i])
|
||||||
} else if value.Valid {
|
} else if value.Valid {
|
||||||
db.Order = int(value.Int64)
|
db.Order = value.Int64
|
||||||
}
|
}
|
||||||
case documentblock.FieldDocumentID:
|
case documentblock.FieldDocumentID:
|
||||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
return fmt.Errorf("unexpected type %T for field document_id", values[i])
|
return fmt.Errorf("unexpected type %T for field document_id", values[i])
|
||||||
} else if value.Valid {
|
} else if value.Valid {
|
||||||
db.DocumentID = int(value.Int64)
|
db.DocumentID = value.Int64
|
||||||
}
|
}
|
||||||
case documentblock.FieldUserID:
|
case documentblock.FieldUserID:
|
||||||
if value, ok := values[i].(*sql.NullString); !ok {
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
@ -66,12 +66,12 @@ func Content(v string) predicate.DocumentBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Order applies equality check predicate on the "order" field. It's identical to OrderEQ.
|
// Order applies equality check predicate on the "order" field. It's identical to OrderEQ.
|
||||||
func Order(v int) predicate.DocumentBlock {
|
func Order(v int64) predicate.DocumentBlock {
|
||||||
return predicate.DocumentBlock(sql.FieldEQ(FieldOrder, v))
|
return predicate.DocumentBlock(sql.FieldEQ(FieldOrder, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
// DocumentID applies equality check predicate on the "document_id" field. It's identical to DocumentIDEQ.
|
// DocumentID applies equality check predicate on the "document_id" field. It's identical to DocumentIDEQ.
|
||||||
func DocumentID(v int) predicate.DocumentBlock {
|
func DocumentID(v int64) predicate.DocumentBlock {
|
||||||
return predicate.DocumentBlock(sql.FieldEQ(FieldDocumentID, v))
|
return predicate.DocumentBlock(sql.FieldEQ(FieldDocumentID, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,82 +221,82 @@ func ContentContainsFold(v string) predicate.DocumentBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// OrderEQ applies the EQ predicate on the "order" field.
|
// OrderEQ applies the EQ predicate on the "order" field.
|
||||||
func OrderEQ(v int) predicate.DocumentBlock {
|
func OrderEQ(v int64) predicate.DocumentBlock {
|
||||||
return predicate.DocumentBlock(sql.FieldEQ(FieldOrder, v))
|
return predicate.DocumentBlock(sql.FieldEQ(FieldOrder, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
// OrderNEQ applies the NEQ predicate on the "order" field.
|
// OrderNEQ applies the NEQ predicate on the "order" field.
|
||||||
func OrderNEQ(v int) predicate.DocumentBlock {
|
func OrderNEQ(v int64) predicate.DocumentBlock {
|
||||||
return predicate.DocumentBlock(sql.FieldNEQ(FieldOrder, v))
|
return predicate.DocumentBlock(sql.FieldNEQ(FieldOrder, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
// OrderIn applies the In predicate on the "order" field.
|
// OrderIn applies the In predicate on the "order" field.
|
||||||
func OrderIn(vs ...int) predicate.DocumentBlock {
|
func OrderIn(vs ...int64) predicate.DocumentBlock {
|
||||||
return predicate.DocumentBlock(sql.FieldIn(FieldOrder, vs...))
|
return predicate.DocumentBlock(sql.FieldIn(FieldOrder, vs...))
|
||||||
}
|
}
|
||||||
|
|
||||||
// OrderNotIn applies the NotIn predicate on the "order" field.
|
// OrderNotIn applies the NotIn predicate on the "order" field.
|
||||||
func OrderNotIn(vs ...int) predicate.DocumentBlock {
|
func OrderNotIn(vs ...int64) predicate.DocumentBlock {
|
||||||
return predicate.DocumentBlock(sql.FieldNotIn(FieldOrder, vs...))
|
return predicate.DocumentBlock(sql.FieldNotIn(FieldOrder, vs...))
|
||||||
}
|
}
|
||||||
|
|
||||||
// OrderGT applies the GT predicate on the "order" field.
|
// OrderGT applies the GT predicate on the "order" field.
|
||||||
func OrderGT(v int) predicate.DocumentBlock {
|
func OrderGT(v int64) predicate.DocumentBlock {
|
||||||
return predicate.DocumentBlock(sql.FieldGT(FieldOrder, v))
|
return predicate.DocumentBlock(sql.FieldGT(FieldOrder, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
// OrderGTE applies the GTE predicate on the "order" field.
|
// OrderGTE applies the GTE predicate on the "order" field.
|
||||||
func OrderGTE(v int) predicate.DocumentBlock {
|
func OrderGTE(v int64) predicate.DocumentBlock {
|
||||||
return predicate.DocumentBlock(sql.FieldGTE(FieldOrder, v))
|
return predicate.DocumentBlock(sql.FieldGTE(FieldOrder, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
// OrderLT applies the LT predicate on the "order" field.
|
// OrderLT applies the LT predicate on the "order" field.
|
||||||
func OrderLT(v int) predicate.DocumentBlock {
|
func OrderLT(v int64) predicate.DocumentBlock {
|
||||||
return predicate.DocumentBlock(sql.FieldLT(FieldOrder, v))
|
return predicate.DocumentBlock(sql.FieldLT(FieldOrder, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
// OrderLTE applies the LTE predicate on the "order" field.
|
// OrderLTE applies the LTE predicate on the "order" field.
|
||||||
func OrderLTE(v int) predicate.DocumentBlock {
|
func OrderLTE(v int64) predicate.DocumentBlock {
|
||||||
return predicate.DocumentBlock(sql.FieldLTE(FieldOrder, v))
|
return predicate.DocumentBlock(sql.FieldLTE(FieldOrder, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
// DocumentIDEQ applies the EQ predicate on the "document_id" field.
|
// DocumentIDEQ applies the EQ predicate on the "document_id" field.
|
||||||
func DocumentIDEQ(v int) predicate.DocumentBlock {
|
func DocumentIDEQ(v int64) predicate.DocumentBlock {
|
||||||
return predicate.DocumentBlock(sql.FieldEQ(FieldDocumentID, v))
|
return predicate.DocumentBlock(sql.FieldEQ(FieldDocumentID, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
// DocumentIDNEQ applies the NEQ predicate on the "document_id" field.
|
// DocumentIDNEQ applies the NEQ predicate on the "document_id" field.
|
||||||
func DocumentIDNEQ(v int) predicate.DocumentBlock {
|
func DocumentIDNEQ(v int64) predicate.DocumentBlock {
|
||||||
return predicate.DocumentBlock(sql.FieldNEQ(FieldDocumentID, v))
|
return predicate.DocumentBlock(sql.FieldNEQ(FieldDocumentID, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
// DocumentIDIn applies the In predicate on the "document_id" field.
|
// DocumentIDIn applies the In predicate on the "document_id" field.
|
||||||
func DocumentIDIn(vs ...int) predicate.DocumentBlock {
|
func DocumentIDIn(vs ...int64) predicate.DocumentBlock {
|
||||||
return predicate.DocumentBlock(sql.FieldIn(FieldDocumentID, vs...))
|
return predicate.DocumentBlock(sql.FieldIn(FieldDocumentID, vs...))
|
||||||
}
|
}
|
||||||
|
|
||||||
// DocumentIDNotIn applies the NotIn predicate on the "document_id" field.
|
// DocumentIDNotIn applies the NotIn predicate on the "document_id" field.
|
||||||
func DocumentIDNotIn(vs ...int) predicate.DocumentBlock {
|
func DocumentIDNotIn(vs ...int64) predicate.DocumentBlock {
|
||||||
return predicate.DocumentBlock(sql.FieldNotIn(FieldDocumentID, vs...))
|
return predicate.DocumentBlock(sql.FieldNotIn(FieldDocumentID, vs...))
|
||||||
}
|
}
|
||||||
|
|
||||||
// DocumentIDGT applies the GT predicate on the "document_id" field.
|
// DocumentIDGT applies the GT predicate on the "document_id" field.
|
||||||
func DocumentIDGT(v int) predicate.DocumentBlock {
|
func DocumentIDGT(v int64) predicate.DocumentBlock {
|
||||||
return predicate.DocumentBlock(sql.FieldGT(FieldDocumentID, v))
|
return predicate.DocumentBlock(sql.FieldGT(FieldDocumentID, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
// DocumentIDGTE applies the GTE predicate on the "document_id" field.
|
// DocumentIDGTE applies the GTE predicate on the "document_id" field.
|
||||||
func DocumentIDGTE(v int) predicate.DocumentBlock {
|
func DocumentIDGTE(v int64) predicate.DocumentBlock {
|
||||||
return predicate.DocumentBlock(sql.FieldGTE(FieldDocumentID, v))
|
return predicate.DocumentBlock(sql.FieldGTE(FieldDocumentID, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
// DocumentIDLT applies the LT predicate on the "document_id" field.
|
// DocumentIDLT applies the LT predicate on the "document_id" field.
|
||||||
func DocumentIDLT(v int) predicate.DocumentBlock {
|
func DocumentIDLT(v int64) predicate.DocumentBlock {
|
||||||
return predicate.DocumentBlock(sql.FieldLT(FieldDocumentID, v))
|
return predicate.DocumentBlock(sql.FieldLT(FieldDocumentID, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
// DocumentIDLTE applies the LTE predicate on the "document_id" field.
|
// DocumentIDLTE applies the LTE predicate on the "document_id" field.
|
||||||
func DocumentIDLTE(v int) predicate.DocumentBlock {
|
func DocumentIDLTE(v int64) predicate.DocumentBlock {
|
||||||
return predicate.DocumentBlock(sql.FieldLTE(FieldDocumentID, v))
|
return predicate.DocumentBlock(sql.FieldLTE(FieldDocumentID, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,13 +34,13 @@ func (dbc *DocumentBlockCreate) SetContent(s string) *DocumentBlockCreate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetOrder sets the "order" field.
|
// SetOrder sets the "order" field.
|
||||||
func (dbc *DocumentBlockCreate) SetOrder(i int) *DocumentBlockCreate {
|
func (dbc *DocumentBlockCreate) SetOrder(i int64) *DocumentBlockCreate {
|
||||||
dbc.mutation.SetOrder(i)
|
dbc.mutation.SetOrder(i)
|
||||||
return dbc
|
return dbc
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDocumentID sets the "document_id" field.
|
// SetDocumentID sets the "document_id" field.
|
||||||
func (dbc *DocumentBlockCreate) SetDocumentID(i int) *DocumentBlockCreate {
|
func (dbc *DocumentBlockCreate) SetDocumentID(i int64) *DocumentBlockCreate {
|
||||||
dbc.mutation.SetDocumentID(i)
|
dbc.mutation.SetDocumentID(i)
|
||||||
return dbc
|
return dbc
|
||||||
}
|
}
|
||||||
@ -197,11 +197,11 @@ func (dbc *DocumentBlockCreate) createSpec() (*DocumentBlock, *sqlgraph.CreateSp
|
|||||||
_node.Content = value
|
_node.Content = value
|
||||||
}
|
}
|
||||||
if value, ok := dbc.mutation.Order(); ok {
|
if value, ok := dbc.mutation.Order(); ok {
|
||||||
_spec.SetField(documentblock.FieldOrder, field.TypeInt, value)
|
_spec.SetField(documentblock.FieldOrder, field.TypeInt64, value)
|
||||||
_node.Order = value
|
_node.Order = value
|
||||||
}
|
}
|
||||||
if value, ok := dbc.mutation.DocumentID(); ok {
|
if value, ok := dbc.mutation.DocumentID(); ok {
|
||||||
_spec.SetField(documentblock.FieldDocumentID, field.TypeInt, value)
|
_spec.SetField(documentblock.FieldDocumentID, field.TypeInt64, value)
|
||||||
_node.DocumentID = value
|
_node.DocumentID = value
|
||||||
}
|
}
|
||||||
if value, ok := dbc.mutation.UserID(); ok {
|
if value, ok := dbc.mutation.UserID(); ok {
|
||||||
|
@ -58,14 +58,14 @@ func (dbu *DocumentBlockUpdate) SetNillableContent(s *string) *DocumentBlockUpda
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetOrder sets the "order" field.
|
// SetOrder sets the "order" field.
|
||||||
func (dbu *DocumentBlockUpdate) SetOrder(i int) *DocumentBlockUpdate {
|
func (dbu *DocumentBlockUpdate) SetOrder(i int64) *DocumentBlockUpdate {
|
||||||
dbu.mutation.ResetOrder()
|
dbu.mutation.ResetOrder()
|
||||||
dbu.mutation.SetOrder(i)
|
dbu.mutation.SetOrder(i)
|
||||||
return dbu
|
return dbu
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetNillableOrder sets the "order" field if the given value is not nil.
|
// SetNillableOrder sets the "order" field if the given value is not nil.
|
||||||
func (dbu *DocumentBlockUpdate) SetNillableOrder(i *int) *DocumentBlockUpdate {
|
func (dbu *DocumentBlockUpdate) SetNillableOrder(i *int64) *DocumentBlockUpdate {
|
||||||
if i != nil {
|
if i != nil {
|
||||||
dbu.SetOrder(*i)
|
dbu.SetOrder(*i)
|
||||||
}
|
}
|
||||||
@ -73,20 +73,20 @@ func (dbu *DocumentBlockUpdate) SetNillableOrder(i *int) *DocumentBlockUpdate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddOrder adds i to the "order" field.
|
// AddOrder adds i to the "order" field.
|
||||||
func (dbu *DocumentBlockUpdate) AddOrder(i int) *DocumentBlockUpdate {
|
func (dbu *DocumentBlockUpdate) AddOrder(i int64) *DocumentBlockUpdate {
|
||||||
dbu.mutation.AddOrder(i)
|
dbu.mutation.AddOrder(i)
|
||||||
return dbu
|
return dbu
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDocumentID sets the "document_id" field.
|
// SetDocumentID sets the "document_id" field.
|
||||||
func (dbu *DocumentBlockUpdate) SetDocumentID(i int) *DocumentBlockUpdate {
|
func (dbu *DocumentBlockUpdate) SetDocumentID(i int64) *DocumentBlockUpdate {
|
||||||
dbu.mutation.ResetDocumentID()
|
dbu.mutation.ResetDocumentID()
|
||||||
dbu.mutation.SetDocumentID(i)
|
dbu.mutation.SetDocumentID(i)
|
||||||
return dbu
|
return dbu
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetNillableDocumentID sets the "document_id" field if the given value is not nil.
|
// SetNillableDocumentID sets the "document_id" field if the given value is not nil.
|
||||||
func (dbu *DocumentBlockUpdate) SetNillableDocumentID(i *int) *DocumentBlockUpdate {
|
func (dbu *DocumentBlockUpdate) SetNillableDocumentID(i *int64) *DocumentBlockUpdate {
|
||||||
if i != nil {
|
if i != nil {
|
||||||
dbu.SetDocumentID(*i)
|
dbu.SetDocumentID(*i)
|
||||||
}
|
}
|
||||||
@ -94,7 +94,7 @@ func (dbu *DocumentBlockUpdate) SetNillableDocumentID(i *int) *DocumentBlockUpda
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddDocumentID adds i to the "document_id" field.
|
// AddDocumentID adds i to the "document_id" field.
|
||||||
func (dbu *DocumentBlockUpdate) AddDocumentID(i int) *DocumentBlockUpdate {
|
func (dbu *DocumentBlockUpdate) AddDocumentID(i int64) *DocumentBlockUpdate {
|
||||||
dbu.mutation.AddDocumentID(i)
|
dbu.mutation.AddDocumentID(i)
|
||||||
return dbu
|
return dbu
|
||||||
}
|
}
|
||||||
@ -225,16 +225,16 @@ func (dbu *DocumentBlockUpdate) sqlSave(ctx context.Context) (n int, err error)
|
|||||||
_spec.SetField(documentblock.FieldContent, field.TypeString, value)
|
_spec.SetField(documentblock.FieldContent, field.TypeString, value)
|
||||||
}
|
}
|
||||||
if value, ok := dbu.mutation.Order(); ok {
|
if value, ok := dbu.mutation.Order(); ok {
|
||||||
_spec.SetField(documentblock.FieldOrder, field.TypeInt, value)
|
_spec.SetField(documentblock.FieldOrder, field.TypeInt64, value)
|
||||||
}
|
}
|
||||||
if value, ok := dbu.mutation.AddedOrder(); ok {
|
if value, ok := dbu.mutation.AddedOrder(); ok {
|
||||||
_spec.AddField(documentblock.FieldOrder, field.TypeInt, value)
|
_spec.AddField(documentblock.FieldOrder, field.TypeInt64, value)
|
||||||
}
|
}
|
||||||
if value, ok := dbu.mutation.DocumentID(); ok {
|
if value, ok := dbu.mutation.DocumentID(); ok {
|
||||||
_spec.SetField(documentblock.FieldDocumentID, field.TypeInt, value)
|
_spec.SetField(documentblock.FieldDocumentID, field.TypeInt64, value)
|
||||||
}
|
}
|
||||||
if value, ok := dbu.mutation.AddedDocumentID(); ok {
|
if value, ok := dbu.mutation.AddedDocumentID(); ok {
|
||||||
_spec.AddField(documentblock.FieldDocumentID, field.TypeInt, value)
|
_spec.AddField(documentblock.FieldDocumentID, field.TypeInt64, value)
|
||||||
}
|
}
|
||||||
if value, ok := dbu.mutation.UserID(); ok {
|
if value, ok := dbu.mutation.UserID(); ok {
|
||||||
_spec.SetField(documentblock.FieldUserID, field.TypeString, value)
|
_spec.SetField(documentblock.FieldUserID, field.TypeString, value)
|
||||||
@ -339,14 +339,14 @@ func (dbuo *DocumentBlockUpdateOne) SetNillableContent(s *string) *DocumentBlock
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetOrder sets the "order" field.
|
// SetOrder sets the "order" field.
|
||||||
func (dbuo *DocumentBlockUpdateOne) SetOrder(i int) *DocumentBlockUpdateOne {
|
func (dbuo *DocumentBlockUpdateOne) SetOrder(i int64) *DocumentBlockUpdateOne {
|
||||||
dbuo.mutation.ResetOrder()
|
dbuo.mutation.ResetOrder()
|
||||||
dbuo.mutation.SetOrder(i)
|
dbuo.mutation.SetOrder(i)
|
||||||
return dbuo
|
return dbuo
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetNillableOrder sets the "order" field if the given value is not nil.
|
// SetNillableOrder sets the "order" field if the given value is not nil.
|
||||||
func (dbuo *DocumentBlockUpdateOne) SetNillableOrder(i *int) *DocumentBlockUpdateOne {
|
func (dbuo *DocumentBlockUpdateOne) SetNillableOrder(i *int64) *DocumentBlockUpdateOne {
|
||||||
if i != nil {
|
if i != nil {
|
||||||
dbuo.SetOrder(*i)
|
dbuo.SetOrder(*i)
|
||||||
}
|
}
|
||||||
@ -354,20 +354,20 @@ func (dbuo *DocumentBlockUpdateOne) SetNillableOrder(i *int) *DocumentBlockUpdat
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddOrder adds i to the "order" field.
|
// AddOrder adds i to the "order" field.
|
||||||
func (dbuo *DocumentBlockUpdateOne) AddOrder(i int) *DocumentBlockUpdateOne {
|
func (dbuo *DocumentBlockUpdateOne) AddOrder(i int64) *DocumentBlockUpdateOne {
|
||||||
dbuo.mutation.AddOrder(i)
|
dbuo.mutation.AddOrder(i)
|
||||||
return dbuo
|
return dbuo
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDocumentID sets the "document_id" field.
|
// SetDocumentID sets the "document_id" field.
|
||||||
func (dbuo *DocumentBlockUpdateOne) SetDocumentID(i int) *DocumentBlockUpdateOne {
|
func (dbuo *DocumentBlockUpdateOne) SetDocumentID(i int64) *DocumentBlockUpdateOne {
|
||||||
dbuo.mutation.ResetDocumentID()
|
dbuo.mutation.ResetDocumentID()
|
||||||
dbuo.mutation.SetDocumentID(i)
|
dbuo.mutation.SetDocumentID(i)
|
||||||
return dbuo
|
return dbuo
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetNillableDocumentID sets the "document_id" field if the given value is not nil.
|
// SetNillableDocumentID sets the "document_id" field if the given value is not nil.
|
||||||
func (dbuo *DocumentBlockUpdateOne) SetNillableDocumentID(i *int) *DocumentBlockUpdateOne {
|
func (dbuo *DocumentBlockUpdateOne) SetNillableDocumentID(i *int64) *DocumentBlockUpdateOne {
|
||||||
if i != nil {
|
if i != nil {
|
||||||
dbuo.SetDocumentID(*i)
|
dbuo.SetDocumentID(*i)
|
||||||
}
|
}
|
||||||
@ -375,7 +375,7 @@ func (dbuo *DocumentBlockUpdateOne) SetNillableDocumentID(i *int) *DocumentBlock
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddDocumentID adds i to the "document_id" field.
|
// AddDocumentID adds i to the "document_id" field.
|
||||||
func (dbuo *DocumentBlockUpdateOne) AddDocumentID(i int) *DocumentBlockUpdateOne {
|
func (dbuo *DocumentBlockUpdateOne) AddDocumentID(i int64) *DocumentBlockUpdateOne {
|
||||||
dbuo.mutation.AddDocumentID(i)
|
dbuo.mutation.AddDocumentID(i)
|
||||||
return dbuo
|
return dbuo
|
||||||
}
|
}
|
||||||
@ -536,16 +536,16 @@ func (dbuo *DocumentBlockUpdateOne) sqlSave(ctx context.Context) (_node *Documen
|
|||||||
_spec.SetField(documentblock.FieldContent, field.TypeString, value)
|
_spec.SetField(documentblock.FieldContent, field.TypeString, value)
|
||||||
}
|
}
|
||||||
if value, ok := dbuo.mutation.Order(); ok {
|
if value, ok := dbuo.mutation.Order(); ok {
|
||||||
_spec.SetField(documentblock.FieldOrder, field.TypeInt, value)
|
_spec.SetField(documentblock.FieldOrder, field.TypeInt64, value)
|
||||||
}
|
}
|
||||||
if value, ok := dbuo.mutation.AddedOrder(); ok {
|
if value, ok := dbuo.mutation.AddedOrder(); ok {
|
||||||
_spec.AddField(documentblock.FieldOrder, field.TypeInt, value)
|
_spec.AddField(documentblock.FieldOrder, field.TypeInt64, value)
|
||||||
}
|
}
|
||||||
if value, ok := dbuo.mutation.DocumentID(); ok {
|
if value, ok := dbuo.mutation.DocumentID(); ok {
|
||||||
_spec.SetField(documentblock.FieldDocumentID, field.TypeInt, value)
|
_spec.SetField(documentblock.FieldDocumentID, field.TypeInt64, value)
|
||||||
}
|
}
|
||||||
if value, ok := dbuo.mutation.AddedDocumentID(); ok {
|
if value, ok := dbuo.mutation.AddedDocumentID(); ok {
|
||||||
_spec.AddField(documentblock.FieldDocumentID, field.TypeInt, value)
|
_spec.AddField(documentblock.FieldDocumentID, field.TypeInt64, value)
|
||||||
}
|
}
|
||||||
if value, ok := dbuo.mutation.UserID(); ok {
|
if value, ok := dbuo.mutation.UserID(); ok {
|
||||||
_spec.SetField(documentblock.FieldUserID, field.TypeString, value)
|
_spec.SetField(documentblock.FieldUserID, field.TypeString, value)
|
||||||
|
@ -13,6 +13,7 @@ var (
|
|||||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||||
{Name: "name", Type: field.TypeString},
|
{Name: "name", Type: field.TypeString},
|
||||||
{Name: "user_id", Type: field.TypeString},
|
{Name: "user_id", Type: field.TypeString},
|
||||||
|
{Name: "library_id", Type: field.TypeInt64},
|
||||||
{Name: "created_at", Type: field.TypeTime},
|
{Name: "created_at", Type: field.TypeTime},
|
||||||
{Name: "updated_at", Type: field.TypeTime},
|
{Name: "updated_at", Type: field.TypeTime},
|
||||||
{Name: "document_block_document", Type: field.TypeInt, Nullable: true},
|
{Name: "document_block_document", Type: field.TypeInt, Nullable: true},
|
||||||
@ -25,7 +26,7 @@ var (
|
|||||||
ForeignKeys: []*schema.ForeignKey{
|
ForeignKeys: []*schema.ForeignKey{
|
||||||
{
|
{
|
||||||
Symbol: "documents_document_blocks_document",
|
Symbol: "documents_document_blocks_document",
|
||||||
Columns: []*schema.Column{DocumentsColumns[5]},
|
Columns: []*schema.Column{DocumentsColumns[6]},
|
||||||
RefColumns: []*schema.Column{DocumentBlocksColumns[0]},
|
RefColumns: []*schema.Column{DocumentBlocksColumns[0]},
|
||||||
OnDelete: schema.SetNull,
|
OnDelete: schema.SetNull,
|
||||||
},
|
},
|
||||||
@ -43,8 +44,8 @@ var (
|
|||||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||||
{Name: "name", Type: field.TypeString},
|
{Name: "name", Type: field.TypeString},
|
||||||
{Name: "content", Type: field.TypeString},
|
{Name: "content", Type: field.TypeString},
|
||||||
{Name: "order", Type: field.TypeInt},
|
{Name: "order", Type: field.TypeInt64},
|
||||||
{Name: "document_id", Type: field.TypeInt},
|
{Name: "document_id", Type: field.TypeInt64},
|
||||||
{Name: "user_id", Type: field.TypeString},
|
{Name: "user_id", Type: field.TypeString},
|
||||||
{Name: "created_at", Type: field.TypeTime},
|
{Name: "created_at", Type: field.TypeTime},
|
||||||
{Name: "updated_at", Type: field.TypeTime},
|
{Name: "updated_at", Type: field.TypeTime},
|
||||||
|
130
ent/mutation.go
130
ent/mutation.go
@ -39,6 +39,8 @@ type DocumentMutation struct {
|
|||||||
id *int
|
id *int
|
||||||
name *string
|
name *string
|
||||||
user_id *string
|
user_id *string
|
||||||
|
library_id *int64
|
||||||
|
addlibrary_id *int64
|
||||||
created_at *time.Time
|
created_at *time.Time
|
||||||
updated_at *time.Time
|
updated_at *time.Time
|
||||||
clearedFields map[string]struct{}
|
clearedFields map[string]struct{}
|
||||||
@ -217,6 +219,62 @@ func (m *DocumentMutation) ResetUserID() {
|
|||||||
m.user_id = nil
|
m.user_id = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetLibraryID sets the "library_id" field.
|
||||||
|
func (m *DocumentMutation) SetLibraryID(i int64) {
|
||||||
|
m.library_id = &i
|
||||||
|
m.addlibrary_id = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// LibraryID returns the value of the "library_id" field in the mutation.
|
||||||
|
func (m *DocumentMutation) LibraryID() (r int64, exists bool) {
|
||||||
|
v := m.library_id
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// OldLibraryID returns the old "library_id" field's value of the Document entity.
|
||||||
|
// If the Document object wasn't provided to the builder, the object is fetched from the database.
|
||||||
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
|
func (m *DocumentMutation) OldLibraryID(ctx context.Context) (v int64, err error) {
|
||||||
|
if !m.op.Is(OpUpdateOne) {
|
||||||
|
return v, errors.New("OldLibraryID is only allowed on UpdateOne operations")
|
||||||
|
}
|
||||||
|
if m.id == nil || m.oldValue == nil {
|
||||||
|
return v, errors.New("OldLibraryID requires an ID field in the mutation")
|
||||||
|
}
|
||||||
|
oldValue, err := m.oldValue(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return v, fmt.Errorf("querying old value for OldLibraryID: %w", err)
|
||||||
|
}
|
||||||
|
return oldValue.LibraryID, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddLibraryID adds i to the "library_id" field.
|
||||||
|
func (m *DocumentMutation) AddLibraryID(i int64) {
|
||||||
|
if m.addlibrary_id != nil {
|
||||||
|
*m.addlibrary_id += i
|
||||||
|
} else {
|
||||||
|
m.addlibrary_id = &i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddedLibraryID returns the value that was added to the "library_id" field in this mutation.
|
||||||
|
func (m *DocumentMutation) AddedLibraryID() (r int64, exists bool) {
|
||||||
|
v := m.addlibrary_id
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetLibraryID resets all changes to the "library_id" field.
|
||||||
|
func (m *DocumentMutation) ResetLibraryID() {
|
||||||
|
m.library_id = nil
|
||||||
|
m.addlibrary_id = nil
|
||||||
|
}
|
||||||
|
|
||||||
// SetCreatedAt sets the "created_at" field.
|
// SetCreatedAt sets the "created_at" field.
|
||||||
func (m *DocumentMutation) SetCreatedAt(t time.Time) {
|
func (m *DocumentMutation) SetCreatedAt(t time.Time) {
|
||||||
m.created_at = &t
|
m.created_at = &t
|
||||||
@ -323,13 +381,16 @@ func (m *DocumentMutation) Type() string {
|
|||||||
// order to get all numeric fields that were incremented/decremented, call
|
// order to get all numeric fields that were incremented/decremented, call
|
||||||
// AddedFields().
|
// AddedFields().
|
||||||
func (m *DocumentMutation) Fields() []string {
|
func (m *DocumentMutation) Fields() []string {
|
||||||
fields := make([]string, 0, 4)
|
fields := make([]string, 0, 5)
|
||||||
if m.name != nil {
|
if m.name != nil {
|
||||||
fields = append(fields, document.FieldName)
|
fields = append(fields, document.FieldName)
|
||||||
}
|
}
|
||||||
if m.user_id != nil {
|
if m.user_id != nil {
|
||||||
fields = append(fields, document.FieldUserID)
|
fields = append(fields, document.FieldUserID)
|
||||||
}
|
}
|
||||||
|
if m.library_id != nil {
|
||||||
|
fields = append(fields, document.FieldLibraryID)
|
||||||
|
}
|
||||||
if m.created_at != nil {
|
if m.created_at != nil {
|
||||||
fields = append(fields, document.FieldCreatedAt)
|
fields = append(fields, document.FieldCreatedAt)
|
||||||
}
|
}
|
||||||
@ -348,6 +409,8 @@ func (m *DocumentMutation) Field(name string) (ent.Value, bool) {
|
|||||||
return m.Name()
|
return m.Name()
|
||||||
case document.FieldUserID:
|
case document.FieldUserID:
|
||||||
return m.UserID()
|
return m.UserID()
|
||||||
|
case document.FieldLibraryID:
|
||||||
|
return m.LibraryID()
|
||||||
case document.FieldCreatedAt:
|
case document.FieldCreatedAt:
|
||||||
return m.CreatedAt()
|
return m.CreatedAt()
|
||||||
case document.FieldUpdatedAt:
|
case document.FieldUpdatedAt:
|
||||||
@ -365,6 +428,8 @@ func (m *DocumentMutation) OldField(ctx context.Context, name string) (ent.Value
|
|||||||
return m.OldName(ctx)
|
return m.OldName(ctx)
|
||||||
case document.FieldUserID:
|
case document.FieldUserID:
|
||||||
return m.OldUserID(ctx)
|
return m.OldUserID(ctx)
|
||||||
|
case document.FieldLibraryID:
|
||||||
|
return m.OldLibraryID(ctx)
|
||||||
case document.FieldCreatedAt:
|
case document.FieldCreatedAt:
|
||||||
return m.OldCreatedAt(ctx)
|
return m.OldCreatedAt(ctx)
|
||||||
case document.FieldUpdatedAt:
|
case document.FieldUpdatedAt:
|
||||||
@ -392,6 +457,13 @@ func (m *DocumentMutation) SetField(name string, value ent.Value) error {
|
|||||||
}
|
}
|
||||||
m.SetUserID(v)
|
m.SetUserID(v)
|
||||||
return nil
|
return nil
|
||||||
|
case document.FieldLibraryID:
|
||||||
|
v, ok := value.(int64)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.SetLibraryID(v)
|
||||||
|
return nil
|
||||||
case document.FieldCreatedAt:
|
case document.FieldCreatedAt:
|
||||||
v, ok := value.(time.Time)
|
v, ok := value.(time.Time)
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -413,13 +485,21 @@ func (m *DocumentMutation) SetField(name string, value ent.Value) error {
|
|||||||
// AddedFields returns all numeric fields that were incremented/decremented during
|
// AddedFields returns all numeric fields that were incremented/decremented during
|
||||||
// this mutation.
|
// this mutation.
|
||||||
func (m *DocumentMutation) AddedFields() []string {
|
func (m *DocumentMutation) AddedFields() []string {
|
||||||
return nil
|
var fields []string
|
||||||
|
if m.addlibrary_id != nil {
|
||||||
|
fields = append(fields, document.FieldLibraryID)
|
||||||
|
}
|
||||||
|
return fields
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddedField returns the numeric value that was incremented/decremented on a field
|
// AddedField returns the numeric value that was incremented/decremented on a field
|
||||||
// with the given name. The second boolean return value indicates that this field
|
// with the given name. The second boolean return value indicates that this field
|
||||||
// was not set, or was not defined in the schema.
|
// was not set, or was not defined in the schema.
|
||||||
func (m *DocumentMutation) AddedField(name string) (ent.Value, bool) {
|
func (m *DocumentMutation) AddedField(name string) (ent.Value, bool) {
|
||||||
|
switch name {
|
||||||
|
case document.FieldLibraryID:
|
||||||
|
return m.AddedLibraryID()
|
||||||
|
}
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -428,6 +508,13 @@ func (m *DocumentMutation) AddedField(name string) (ent.Value, bool) {
|
|||||||
// type.
|
// type.
|
||||||
func (m *DocumentMutation) AddField(name string, value ent.Value) error {
|
func (m *DocumentMutation) AddField(name string, value ent.Value) error {
|
||||||
switch name {
|
switch name {
|
||||||
|
case document.FieldLibraryID:
|
||||||
|
v, ok := value.(int64)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.AddLibraryID(v)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
return fmt.Errorf("unknown Document numeric field %s", name)
|
return fmt.Errorf("unknown Document numeric field %s", name)
|
||||||
}
|
}
|
||||||
@ -461,6 +548,9 @@ func (m *DocumentMutation) ResetField(name string) error {
|
|||||||
case document.FieldUserID:
|
case document.FieldUserID:
|
||||||
m.ResetUserID()
|
m.ResetUserID()
|
||||||
return nil
|
return nil
|
||||||
|
case document.FieldLibraryID:
|
||||||
|
m.ResetLibraryID()
|
||||||
|
return nil
|
||||||
case document.FieldCreatedAt:
|
case document.FieldCreatedAt:
|
||||||
m.ResetCreatedAt()
|
m.ResetCreatedAt()
|
||||||
return nil
|
return nil
|
||||||
@ -527,10 +617,10 @@ type DocumentBlockMutation struct {
|
|||||||
id *int
|
id *int
|
||||||
name *string
|
name *string
|
||||||
content *string
|
content *string
|
||||||
_order *int
|
_order *int64
|
||||||
add_order *int
|
add_order *int64
|
||||||
document_id *int
|
document_id *int64
|
||||||
adddocument_id *int
|
adddocument_id *int64
|
||||||
user_id *string
|
user_id *string
|
||||||
created_at *time.Time
|
created_at *time.Time
|
||||||
updated_at *time.Time
|
updated_at *time.Time
|
||||||
@ -714,13 +804,13 @@ func (m *DocumentBlockMutation) ResetContent() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetOrder sets the "order" field.
|
// SetOrder sets the "order" field.
|
||||||
func (m *DocumentBlockMutation) SetOrder(i int) {
|
func (m *DocumentBlockMutation) SetOrder(i int64) {
|
||||||
m._order = &i
|
m._order = &i
|
||||||
m.add_order = nil
|
m.add_order = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Order returns the value of the "order" field in the mutation.
|
// Order returns the value of the "order" field in the mutation.
|
||||||
func (m *DocumentBlockMutation) Order() (r int, exists bool) {
|
func (m *DocumentBlockMutation) Order() (r int64, exists bool) {
|
||||||
v := m._order
|
v := m._order
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return
|
return
|
||||||
@ -731,7 +821,7 @@ func (m *DocumentBlockMutation) Order() (r int, exists bool) {
|
|||||||
// OldOrder returns the old "order" field's value of the DocumentBlock entity.
|
// OldOrder returns the old "order" field's value of the DocumentBlock entity.
|
||||||
// If the DocumentBlock object wasn't provided to the builder, the object is fetched from the database.
|
// If the DocumentBlock object wasn't provided to the builder, the object is fetched from the database.
|
||||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
func (m *DocumentBlockMutation) OldOrder(ctx context.Context) (v int, err error) {
|
func (m *DocumentBlockMutation) OldOrder(ctx context.Context) (v int64, err error) {
|
||||||
if !m.op.Is(OpUpdateOne) {
|
if !m.op.Is(OpUpdateOne) {
|
||||||
return v, errors.New("OldOrder is only allowed on UpdateOne operations")
|
return v, errors.New("OldOrder is only allowed on UpdateOne operations")
|
||||||
}
|
}
|
||||||
@ -746,7 +836,7 @@ func (m *DocumentBlockMutation) OldOrder(ctx context.Context) (v int, err error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddOrder adds i to the "order" field.
|
// AddOrder adds i to the "order" field.
|
||||||
func (m *DocumentBlockMutation) AddOrder(i int) {
|
func (m *DocumentBlockMutation) AddOrder(i int64) {
|
||||||
if m.add_order != nil {
|
if m.add_order != nil {
|
||||||
*m.add_order += i
|
*m.add_order += i
|
||||||
} else {
|
} else {
|
||||||
@ -755,7 +845,7 @@ func (m *DocumentBlockMutation) AddOrder(i int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddedOrder returns the value that was added to the "order" field in this mutation.
|
// AddedOrder returns the value that was added to the "order" field in this mutation.
|
||||||
func (m *DocumentBlockMutation) AddedOrder() (r int, exists bool) {
|
func (m *DocumentBlockMutation) AddedOrder() (r int64, exists bool) {
|
||||||
v := m.add_order
|
v := m.add_order
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return
|
return
|
||||||
@ -770,13 +860,13 @@ func (m *DocumentBlockMutation) ResetOrder() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetDocumentID sets the "document_id" field.
|
// SetDocumentID sets the "document_id" field.
|
||||||
func (m *DocumentBlockMutation) SetDocumentID(i int) {
|
func (m *DocumentBlockMutation) SetDocumentID(i int64) {
|
||||||
m.document_id = &i
|
m.document_id = &i
|
||||||
m.adddocument_id = nil
|
m.adddocument_id = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DocumentID returns the value of the "document_id" field in the mutation.
|
// DocumentID returns the value of the "document_id" field in the mutation.
|
||||||
func (m *DocumentBlockMutation) DocumentID() (r int, exists bool) {
|
func (m *DocumentBlockMutation) DocumentID() (r int64, exists bool) {
|
||||||
v := m.document_id
|
v := m.document_id
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return
|
return
|
||||||
@ -787,7 +877,7 @@ func (m *DocumentBlockMutation) DocumentID() (r int, exists bool) {
|
|||||||
// OldDocumentID returns the old "document_id" field's value of the DocumentBlock entity.
|
// OldDocumentID returns the old "document_id" field's value of the DocumentBlock entity.
|
||||||
// If the DocumentBlock object wasn't provided to the builder, the object is fetched from the database.
|
// If the DocumentBlock object wasn't provided to the builder, the object is fetched from the database.
|
||||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||||
func (m *DocumentBlockMutation) OldDocumentID(ctx context.Context) (v int, err error) {
|
func (m *DocumentBlockMutation) OldDocumentID(ctx context.Context) (v int64, err error) {
|
||||||
if !m.op.Is(OpUpdateOne) {
|
if !m.op.Is(OpUpdateOne) {
|
||||||
return v, errors.New("OldDocumentID is only allowed on UpdateOne operations")
|
return v, errors.New("OldDocumentID is only allowed on UpdateOne operations")
|
||||||
}
|
}
|
||||||
@ -802,7 +892,7 @@ func (m *DocumentBlockMutation) OldDocumentID(ctx context.Context) (v int, err e
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddDocumentID adds i to the "document_id" field.
|
// AddDocumentID adds i to the "document_id" field.
|
||||||
func (m *DocumentBlockMutation) AddDocumentID(i int) {
|
func (m *DocumentBlockMutation) AddDocumentID(i int64) {
|
||||||
if m.adddocument_id != nil {
|
if m.adddocument_id != nil {
|
||||||
*m.adddocument_id += i
|
*m.adddocument_id += i
|
||||||
} else {
|
} else {
|
||||||
@ -811,7 +901,7 @@ func (m *DocumentBlockMutation) AddDocumentID(i int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddedDocumentID returns the value that was added to the "document_id" field in this mutation.
|
// AddedDocumentID returns the value that was added to the "document_id" field in this mutation.
|
||||||
func (m *DocumentBlockMutation) AddedDocumentID() (r int, exists bool) {
|
func (m *DocumentBlockMutation) AddedDocumentID() (r int64, exists bool) {
|
||||||
v := m.adddocument_id
|
v := m.adddocument_id
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return
|
return
|
||||||
@ -1112,14 +1202,14 @@ func (m *DocumentBlockMutation) SetField(name string, value ent.Value) error {
|
|||||||
m.SetContent(v)
|
m.SetContent(v)
|
||||||
return nil
|
return nil
|
||||||
case documentblock.FieldOrder:
|
case documentblock.FieldOrder:
|
||||||
v, ok := value.(int)
|
v, ok := value.(int64)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
}
|
}
|
||||||
m.SetOrder(v)
|
m.SetOrder(v)
|
||||||
return nil
|
return nil
|
||||||
case documentblock.FieldDocumentID:
|
case documentblock.FieldDocumentID:
|
||||||
v, ok := value.(int)
|
v, ok := value.(int64)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
}
|
}
|
||||||
@ -1182,14 +1272,14 @@ func (m *DocumentBlockMutation) AddedField(name string) (ent.Value, bool) {
|
|||||||
func (m *DocumentBlockMutation) AddField(name string, value ent.Value) error {
|
func (m *DocumentBlockMutation) AddField(name string, value ent.Value) error {
|
||||||
switch name {
|
switch name {
|
||||||
case documentblock.FieldOrder:
|
case documentblock.FieldOrder:
|
||||||
v, ok := value.(int)
|
v, ok := value.(int64)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
}
|
}
|
||||||
m.AddOrder(v)
|
m.AddOrder(v)
|
||||||
return nil
|
return nil
|
||||||
case documentblock.FieldDocumentID:
|
case documentblock.FieldDocumentID:
|
||||||
v, ok := value.(int)
|
v, ok := value.(int64)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
}
|
}
|
||||||
|
@ -18,11 +18,11 @@ func init() {
|
|||||||
documentFields := schema.Document{}.Fields()
|
documentFields := schema.Document{}.Fields()
|
||||||
_ = documentFields
|
_ = documentFields
|
||||||
// documentDescCreatedAt is the schema descriptor for created_at field.
|
// documentDescCreatedAt is the schema descriptor for created_at field.
|
||||||
documentDescCreatedAt := documentFields[2].Descriptor()
|
documentDescCreatedAt := documentFields[3].Descriptor()
|
||||||
// document.DefaultCreatedAt holds the default value on creation for the created_at field.
|
// document.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||||
document.DefaultCreatedAt = documentDescCreatedAt.Default.(func() time.Time)
|
document.DefaultCreatedAt = documentDescCreatedAt.Default.(func() time.Time)
|
||||||
// documentDescUpdatedAt is the schema descriptor for updated_at field.
|
// documentDescUpdatedAt is the schema descriptor for updated_at field.
|
||||||
documentDescUpdatedAt := documentFields[3].Descriptor()
|
documentDescUpdatedAt := documentFields[4].Descriptor()
|
||||||
// document.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
// document.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
||||||
document.DefaultUpdatedAt = documentDescUpdatedAt.Default.(func() time.Time)
|
document.DefaultUpdatedAt = documentDescUpdatedAt.Default.(func() time.Time)
|
||||||
documentblockFields := schema.DocumentBlock{}.Fields()
|
documentblockFields := schema.DocumentBlock{}.Fields()
|
||||||
|
@ -17,6 +17,7 @@ func (Document) Fields() []ent.Field {
|
|||||||
return []ent.Field{
|
return []ent.Field{
|
||||||
field.String("name"),
|
field.String("name"),
|
||||||
field.String("user_id"),
|
field.String("user_id"),
|
||||||
|
field.Int64("library_id"),
|
||||||
|
|
||||||
field.Time("created_at").Default(time.Now),
|
field.Time("created_at").Default(time.Now),
|
||||||
field.Time("updated_at").Default(time.Now),
|
field.Time("updated_at").Default(time.Now),
|
||||||
|
@ -19,9 +19,9 @@ func (DocumentBlock) Fields() []ent.Field {
|
|||||||
field.String("name"),
|
field.String("name"),
|
||||||
field.String("content"),
|
field.String("content"),
|
||||||
// order
|
// order
|
||||||
field.Int("order"),
|
field.Int64("order"),
|
||||||
// document id
|
// document id
|
||||||
field.Int("document_id"),
|
field.Int64("document_id"),
|
||||||
field.String("user_id"),
|
field.String("user_id"),
|
||||||
|
|
||||||
field.Time("created_at").Default(time.Now),
|
field.Time("created_at").Default(time.Now),
|
||||||
|
@ -22,16 +22,16 @@ var libraryLogic = logic.NewLibraryLogic()
|
|||||||
// @Summary 获取当前用户的资料库
|
// @Summary 获取当前用户的资料库
|
||||||
// @Success 200 {array} models.ListLibraryResponse
|
// @Success 200 {array} models.ListLibraryResponse
|
||||||
// @Router /library [get]
|
// @Router /library [get]
|
||||||
func (c *Controller) Library(ctx *gin.Context) {
|
//func (c *Controller) Library(ctx *gin.Context) {
|
||||||
libraries, _ := libraryLogic.ListLibrary(ctx)
|
// libraries, _ := libraryLogic.ListLibrary(ctx)
|
||||||
|
//
|
||||||
libraryResponse := models.ListLibraryResponse{
|
// libraryResponse := models.ListLibraryResponse{
|
||||||
Libraries: libraries,
|
// Libraries: libraries,
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
//helper.Response(ctx, http.StatusOK, libraryResponse)
|
// //helper.Response(ctx, http.StatusOK, libraryResponse)
|
||||||
ctx.JSON(http.StatusOK, libraryResponse)
|
// ctx.JSON(http.StatusOK, libraryResponse)
|
||||||
}
|
//}
|
||||||
|
|
||||||
// CreateLibrary 创建一个资料库 godoc
|
// CreateLibrary 创建一个资料库 godoc
|
||||||
// @Summary 创建一个资料库
|
// @Summary 创建一个资料库
|
||||||
|
@ -2,24 +2,56 @@ package logic
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"leafdev.top/leaf/rag/ent"
|
"leafdev.top/leaf/rag/ent"
|
||||||
"leafdev.top/leaf/rag/ent/document"
|
"leafdev.top/leaf/rag/ent/document"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DocumentLogic struct {
|
type DocumentLogic struct {
|
||||||
|
LibraryLogic LibraryLogic
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDocumentLogic() *DocumentLogic {
|
func NewDocumentLogic() *DocumentLogic {
|
||||||
return &DocumentLogic{}
|
return &DocumentLogic{
|
||||||
|
LibraryLogic: *NewLibraryLogic(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (DocumentLogic) ListDocument(ctx context.Context) ([]*ent.Document, error) {
|
func (d DocumentLogic) ListDocument(ctx context.Context, libraryId int64) ([]*ent.Document, error) {
|
||||||
return orm.Document.Query().Where(document.UserIDEQ(GetUserId(ctx))).All(ctx)
|
library, err := d.LibraryLogic.ExistsByUser(ctx, int(libraryId))
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !library {
|
||||||
|
return nil, errors.New("我们在你的账户下找不到这个资料库")
|
||||||
|
}
|
||||||
|
|
||||||
|
return orm.Document.Query().Where(
|
||||||
|
document.UserIDEQ(GetUserId(ctx)),
|
||||||
|
document.LibraryIDEQ(libraryId),
|
||||||
|
).All(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (DocumentLogic) CreateDocument(ctx context.Context, name string) (*ent.Document, error) {
|
func (d DocumentLogic) CreateDocument(ctx context.Context, libraryId int64, name string) (*ent.Document, error) {
|
||||||
|
// 检查 Library 是否存在
|
||||||
|
exists, err := d.LibraryLogic.ExistsByUser(ctx, int(libraryId))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !exists {
|
||||||
|
return nil, errors.New("library not exists")
|
||||||
|
}
|
||||||
|
|
||||||
|
if name == "" {
|
||||||
|
return nil, errors.New("name cannot be empty")
|
||||||
|
}
|
||||||
|
|
||||||
return orm.Document.Create().
|
return orm.Document.Create().
|
||||||
SetName(name).
|
SetName(name).
|
||||||
SetUserID(GetUserId(ctx)).
|
SetUserID(GetUserId(ctx)).
|
||||||
|
SetLibraryID(libraryId).
|
||||||
Save(ctx)
|
Save(ctx)
|
||||||
}
|
}
|
||||||
|
@ -5,17 +5,23 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"leafdev.top/leaf/rag/ent"
|
"leafdev.top/leaf/rag/ent"
|
||||||
"leafdev.top/leaf/rag/ent/library"
|
"leafdev.top/leaf/rag/ent/library"
|
||||||
|
"leafdev.top/leaf/rag/internal/providers/helper"
|
||||||
)
|
)
|
||||||
|
|
||||||
type LibraryLogic struct {
|
type LibraryLogic struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var pageSize = 10
|
||||||
|
|
||||||
func NewLibraryLogic() *LibraryLogic {
|
func NewLibraryLogic() *LibraryLogic {
|
||||||
return &LibraryLogic{}
|
return &LibraryLogic{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LibraryLogic) ListLibrary(ctx context.Context) ([]*ent.Library, error) {
|
func (l *LibraryLogic) ListLibrary(ctx context.Context, page int) ([]*ent.Library, error) {
|
||||||
return orm.Library.Query().Where(library.UserID(GetUserId(ctx))).All(ctx)
|
return orm.Library.Query().Where(library.UserID(GetUserId(ctx))).
|
||||||
|
Offset(helper.Offset(page, pageSize)).
|
||||||
|
Limit(pageSize).
|
||||||
|
All(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LibraryLogic) CreateLibrary(ctx context.Context, name string) (*ent.Library, error) {
|
func (l *LibraryLogic) CreateLibrary(ctx context.Context, name string) (*ent.Library, error) {
|
||||||
@ -29,3 +35,25 @@ func (l *LibraryLogic) CreateLibrary(ctx context.Context, name string) (*ent.Lib
|
|||||||
SetUserID(GetUserId(ctx)).
|
SetUserID(GetUserId(ctx)).
|
||||||
Save(ctx)
|
Save(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l *LibraryLogic) DeleteLibrary(ctx context.Context, id int) error {
|
||||||
|
return orm.Library.DeleteOneID(id).Exec(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *LibraryLogic) UpdateLibrary(ctx context.Context, id int, name string) (*ent.Library, error) {
|
||||||
|
return orm.Library.UpdateOneID(id).
|
||||||
|
SetName(name).
|
||||||
|
Save(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *LibraryLogic) GetLibrary(ctx context.Context, id int) (*ent.Library, error) {
|
||||||
|
return orm.Library.Get(ctx, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *LibraryLogic) Exists(ctx context.Context, id int) (bool, error) {
|
||||||
|
return orm.Library.Query().Where(library.ID(id)).Exist(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *LibraryLogic) ExistsByUser(ctx context.Context, libraryId int) (bool, error) {
|
||||||
|
return orm.Library.Query().Where(library.IDEQ(libraryId), library.UserIDEQ(GetUserId(ctx))).Exist(ctx)
|
||||||
|
}
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
-- +goose Up
|
|
||||||
-- create "libraries" table
|
|
||||||
CREATE TABLE "libraries" ("id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, "name" character varying NOT NULL, "user_id" bigint NOT NULL, "created_at" timestamptz NOT NULL, "updated_at" timestamptz NOT NULL, PRIMARY KEY ("id"));
|
|
||||||
-- create index "library_name_user_id" to table: "libraries"
|
|
||||||
CREATE INDEX "library_name_user_id" ON "libraries" ("name", "user_id");
|
|
||||||
|
|
||||||
-- +goose Down
|
|
||||||
-- reverse: create index "library_name_user_id" to table: "libraries"
|
|
||||||
DROP INDEX "library_name_user_id";
|
|
||||||
-- reverse: create "libraries" table
|
|
||||||
DROP TABLE "libraries";
|
|
@ -1,7 +0,0 @@
|
|||||||
-- +goose Up
|
|
||||||
-- modify "libraries" table
|
|
||||||
ALTER TABLE "libraries" ALTER COLUMN "user_id" TYPE character varying;
|
|
||||||
|
|
||||||
-- +goose Down
|
|
||||||
-- reverse: modify "libraries" table
|
|
||||||
ALTER TABLE "libraries" ALTER COLUMN "user_id" TYPE bigint;
|
|
@ -1,19 +0,0 @@
|
|||||||
-- +goose Up
|
|
||||||
-- create "document_blocks" table
|
|
||||||
CREATE TABLE "document_blocks" ("id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, "name" character varying NOT NULL, "content" character varying NOT NULL, "document_id" bigint NOT NULL, "user_id" character varying NOT NULL, "created_at" timestamptz NOT NULL, "updated_at" timestamptz NOT NULL, PRIMARY KEY ("id"));
|
|
||||||
-- create index "documentblock_name_user_id" to table: "document_blocks"
|
|
||||||
CREATE INDEX "documentblock_name_user_id" ON "document_blocks" ("name", "user_id");
|
|
||||||
-- create "documents" table
|
|
||||||
CREATE TABLE "documents" ("id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, "name" character varying NOT NULL, "user_id" character varying NOT NULL, "created_at" timestamptz NOT NULL, "updated_at" timestamptz NOT NULL, "document_block_document" bigint NULL, PRIMARY KEY ("id"), CONSTRAINT "documents_document_blocks_document" FOREIGN KEY ("document_block_document") REFERENCES "document_blocks" ("id") ON DELETE SET NULL);
|
|
||||||
-- create index "document_name_user_id" to table: "documents"
|
|
||||||
CREATE INDEX "document_name_user_id" ON "documents" ("name", "user_id");
|
|
||||||
|
|
||||||
-- +goose Down
|
|
||||||
-- reverse: create index "document_name_user_id" to table: "documents"
|
|
||||||
DROP INDEX "document_name_user_id";
|
|
||||||
-- reverse: create "documents" table
|
|
||||||
DROP TABLE "documents";
|
|
||||||
-- reverse: create index "documentblock_name_user_id" to table: "document_blocks"
|
|
||||||
DROP INDEX "documentblock_name_user_id";
|
|
||||||
-- reverse: create "document_blocks" table
|
|
||||||
DROP TABLE "document_blocks";
|
|
@ -1,11 +0,0 @@
|
|||||||
-- +goose Up
|
|
||||||
-- modify "document_blocks" table
|
|
||||||
ALTER TABLE "document_blocks" ADD COLUMN "order" bigint NOT NULL;
|
|
||||||
-- create index "documentblock_name_user_id_order" to table: "document_blocks"
|
|
||||||
CREATE INDEX "documentblock_name_user_id_order" ON "document_blocks" ("name", "user_id", "order");
|
|
||||||
|
|
||||||
-- +goose Down
|
|
||||||
-- reverse: create index "documentblock_name_user_id_order" to table: "document_blocks"
|
|
||||||
DROP INDEX "documentblock_name_user_id_order";
|
|
||||||
-- reverse: modify "document_blocks" table
|
|
||||||
ALTER TABLE "document_blocks" DROP COLUMN "order";
|
|
27
internal/migrations/20240720155522_init.sql
Normal file
27
internal/migrations/20240720155522_init.sql
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
-- +goose Up
|
||||||
|
-- create "document_blocks" table
|
||||||
|
CREATE TABLE "document_blocks" ("id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, "name" character varying NOT NULL, "content" character varying NOT NULL, "order" bigint NOT NULL, "document_id" bigint NOT NULL, "user_id" character varying NOT NULL, "created_at" timestamptz NOT NULL, "updated_at" timestamptz NOT NULL, PRIMARY KEY ("id"));
|
||||||
|
-- create index "documentblock_name_user_id_order" to table: "document_blocks"
|
||||||
|
CREATE INDEX "documentblock_name_user_id_order" ON "document_blocks" ("name", "user_id", "order");
|
||||||
|
-- create "libraries" table
|
||||||
|
CREATE TABLE "libraries" ("id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, "name" character varying NOT NULL, "user_id" character varying NOT NULL, "created_at" timestamptz NOT NULL, "updated_at" timestamptz NOT NULL, PRIMARY KEY ("id"));
|
||||||
|
-- create index "library_name_user_id" to table: "libraries"
|
||||||
|
CREATE INDEX "library_name_user_id" ON "libraries" ("name", "user_id");
|
||||||
|
-- create "documents" table
|
||||||
|
CREATE TABLE "documents" ("id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, "name" character varying NOT NULL, "user_id" character varying NOT NULL, "library_id" bigint NOT NULL, "created_at" timestamptz NOT NULL, "updated_at" timestamptz NOT NULL, "document_block_document" bigint NULL, PRIMARY KEY ("id"), CONSTRAINT "documents_document_blocks_document" FOREIGN KEY ("document_block_document") REFERENCES "document_blocks" ("id") ON DELETE SET NULL);
|
||||||
|
-- create index "document_name_user_id" to table: "documents"
|
||||||
|
CREATE INDEX "document_name_user_id" ON "documents" ("name", "user_id");
|
||||||
|
|
||||||
|
-- +goose Down
|
||||||
|
-- reverse: create index "document_name_user_id" to table: "documents"
|
||||||
|
DROP INDEX "document_name_user_id";
|
||||||
|
-- reverse: create "documents" table
|
||||||
|
DROP TABLE "documents";
|
||||||
|
-- reverse: create index "library_name_user_id" to table: "libraries"
|
||||||
|
DROP INDEX "library_name_user_id";
|
||||||
|
-- reverse: create "libraries" table
|
||||||
|
DROP TABLE "libraries";
|
||||||
|
-- reverse: create index "documentblock_name_user_id_order" to table: "document_blocks"
|
||||||
|
DROP INDEX "documentblock_name_user_id_order";
|
||||||
|
-- reverse: create "document_blocks" table
|
||||||
|
DROP TABLE "document_blocks";
|
@ -1,5 +1,2 @@
|
|||||||
h1:sLEQ6Lxd6zOalx8i43YLFGrjyKJrnXXnj8KDE/eqF3A=
|
h1:hDIlYDlNwP2WQt4WZ9vaeH5D8IAoeLPMBHidHnSKaIs=
|
||||||
20240714155720_create_library.sql h1:nfzvzMxwqJRhmvUQSnXcK/LZDyAfy/vnjx7ZD2vY3AU=
|
20240720155522_init.sql h1:CKqDLw2sVT+NMqnmrvwtkmbHwNFJTUbdR5q0OtoxF1k=
|
||||||
20240714164619_update_user_id.sql h1:AUCFOY9OVkR4W/sFc7Ipb5Cz3xR4gY61jDuTN4MN7w8=
|
|
||||||
20240720092815_add_documents_tables.sql h1:S0OeUzCLWqXtA1Wi2Wvmlj/2eg2Kl0NkPNRy7Mu+2MY=
|
|
||||||
20240720093157_add_order_to_document_blocks.sql h1:6CHgxARw5yXmXfHTzFFPxqZZ8bWl3g76KHXlB3XYeLQ=
|
|
||||||
|
@ -45,7 +45,7 @@ func InitApiRoutes() {
|
|||||||
authorizedApiV1.Use(http.RequireJWTIDToken)
|
authorizedApiV1.Use(http.RequireJWTIDToken)
|
||||||
{
|
{
|
||||||
authorizedApiV1.GET("/user", userController.CurrentUser)
|
authorizedApiV1.GET("/user", userController.CurrentUser)
|
||||||
authorizedApiV1.GET("/library", libraryController.Library)
|
//authorizedApiV1.GET("/library", libraryController.Library)
|
||||||
authorizedApiV1.POST("/library", libraryController.CreateLibrary)
|
authorizedApiV1.POST("/library", libraryController.CreateLibrary)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (Service) ListDocument(ctx context.Context, req *ragApi.ListDocumentRequest) (*ragApi.ListDocumentResponse, error) {
|
func (Service) ListDocument(ctx context.Context, req *ragApi.ListDocumentRequest) (*ragApi.ListDocumentResponse, error) {
|
||||||
document, err := documentLogic.ListDocument(ctx)
|
document, err := documentLogic.ListDocument(ctx, req.LibraryId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -18,6 +18,7 @@ func (Service) ListDocument(ctx context.Context, req *ragApi.ListDocumentRequest
|
|||||||
Id: int64(document.ID),
|
Id: int64(document.ID),
|
||||||
Name: document.Name,
|
Name: document.Name,
|
||||||
UserId: document.UserID,
|
UserId: document.UserID,
|
||||||
|
LibraryId: document.LibraryID,
|
||||||
CreatedAt: document.CreatedAt.String(),
|
CreatedAt: document.CreatedAt.String(),
|
||||||
UpdatedAt: document.UpdatedAt.String(),
|
UpdatedAt: document.UpdatedAt.String(),
|
||||||
}
|
}
|
||||||
@ -28,7 +29,7 @@ func (Service) ListDocument(ctx context.Context, req *ragApi.ListDocumentRequest
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (Service) CreateDocument(ctx context.Context, req *ragApi.CreateDocumentRequest) (*ragApi.CreateDocumentResponse, error) {
|
func (Service) CreateDocument(ctx context.Context, req *ragApi.CreateDocumentRequest) (*ragApi.CreateDocumentResponse, error) {
|
||||||
document, err := documentLogic.CreateDocument(ctx, req.Name)
|
document, err := documentLogic.CreateDocument(ctx, req.LibraryId, req.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,11 @@ package rag
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/mitchellh/mapstructure"
|
|
||||||
ragApi "leafdev.top/leaf/rag/api/rag"
|
ragApi "leafdev.top/leaf/rag/api/rag"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (Service) ListLibrary(ctx context.Context, _ *ragApi.ListLibraryRequest) (*ragApi.ListLibraryResponse, error) {
|
func (Service) ListLibrary(ctx context.Context, req *ragApi.ListLibraryRequest) (*ragApi.ListLibraryResponse, error) {
|
||||||
libraries, err := libraryLogic.ListLibrary(ctx)
|
libraries, err := libraryLogic.ListLibrary(ctx, int(req.Page))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -35,10 +34,14 @@ func (Service) CreateLibrary(ctx context.Context, req *ragApi.CreateLibraryReque
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var libraryApiResponse ragApi.CreateLibraryResponse
|
var libraryApiResponse = ragApi.CreateLibraryResponse{
|
||||||
err = mapstructure.Decode(library, &libraryApiResponse)
|
Library: &ragApi.Library{
|
||||||
if err != nil {
|
Id: int64(library.ID),
|
||||||
return nil, err
|
Name: library.Name,
|
||||||
|
UserId: library.UserID,
|
||||||
|
CreatedAt: library.CreatedAt.String(),
|
||||||
|
UpdatedAt: library.UpdatedAt.String(),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
return &libraryApiResponse, nil
|
return &libraryApiResponse, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user