我正在开发一个库存应用程序,其中需要生成一个独特的自动增量值来创建产品ID。
很少混淆如何使用firebase作为后端服务生成自定义自动增量ID。
答案 0 :(得分:3)
与自动增量列等效的Firebase数据库称为推送ID 。当您致电Private Sub Worksheet_Change(ByVal Target As Range)
Dim Rng1 As Range
Set Rng1 = Range("C10:AA36,C44:AA68")
If Not Intersect(Target, Rng1) Is Nothing Then
Application.EnableEvents = False
If Len(Target.Value) > 0 Then
' -- first clear the previous formatting --
Target.Borders.LineStyle = xlNone
Target.Borders(xlDiagonalDown).LineStyle = xlNone
Select Case Target.Value
Case 0 ' create diagonal line
Target.Borders(xlDiagonalDown).LineStyle = xlContinuous
Case 1 ' create right triangle
Target.Borders(xlDiagonalDown).LineStyle = xlContinuous
Target.Borders(xlEdgeBottom).LineStyle = xlContinuous
Target.Borders(xlEdgeLeft).LineStyle = xlContinuous
Case 2 ' create up-side down triangle
Target.Borders(xlDiagonalDown).LineStyle = xlContinuous
Target.Borders(xlEdgeTop).LineStyle = xlContinuous
Target.Borders(xlEdgeRight).LineStyle = xlContinuous
End Select
End If
End If
Application.EnableEvents = True
End Sub
(或在iOS push()
上)时,会生成这些密钥,它们是:
但与SQL数据库中的自动增量列不同:
而不是childByAutoId
,1
,2
,您将获得3
,"-KqB_B7Rh8cTYQxihbpb"
,"-KqB_CfSXYZ3kp0a_WlT"
等值。虽然他们可能有点难以习惯,但这些优点非常值得。
我建议您在这两篇博文中阅读更多内容:
答案 1 :(得分:0)
每次在Firebase中插入数据时,都会为对象生成唯一ID(UUID)。建议的做法是使用firebase-generated UUIDs或custom UUID,而不是自动增量ID(检查此question)