Documentation ¶
Index ¶
- Constants
- Variables
- func Register(name string, driver Driver)
- type ACLLevel
- type APSSetting
- type AccessModel
- type AppleAlert
- type Asset
- type AuthInfo
- type Conn
- type CountFunc
- type DBHookFunc
- type Data
- type DataType
- type Database
- type Device
- type DistanceFunc
- type Driver
- type DriverFunc
- type Expression
- type ExpressionType
- type FieldType
- type Func
- type Location
- type MemoryRows
- type NotificationInfo
- type Operator
- type Predicate
- type Query
- type QueryConfig
- type Record
- type RecordACL
- type RecordACLEntry
- type RecordEvent
- type RecordHookEvent
- type RecordID
- type RecordSchema
- type Reference
- type Rows
- type RowsIter
- type Sequence
- type Sort
- type SortOrder
- type Subscription
- type TxDatabase
- type UserInfo
- func (info *UserInfo) GetProvidedAuthData(principalID string) map[string]interface{}
- func (info UserInfo) IsSamePassword(password string) bool
- func (info *UserInfo) RemoveProvidedAuthData(principalID string)
- func (info *UserInfo) SetPassword(password string)
- func (info *UserInfo) SetProvidedAuthData(principalID string, authData map[string]interface{})
- type UserRelationFunc
Constants ¶
const ( Ascending SortOrder = iota Descending Asc = Ascending Desc = Descending )
A list of SordOrder, their meaning is self descriptive.
Variables ¶
var EmptyRows = NewRows(emptyRowsIter(0))
EmptyRows is a convenient variable that acts as an empty Rows. Useful for skydb implementators and testing.
var ErrDatabaseTxDidBegin = errors.New("skydb: a transaction has already begun")
var ErrDatabaseTxDidNotBegin = errors.New("skydb: a transaction has not begun")
var ErrDatabaseTxDone = errors.New("skydb: Database's transaction has already commited or rolled back")
var ErrDeviceNotFound = errors.New("skydb: Specific device not found")
ErrDeviceNotFound is returned by Conn.GetDevice, Conn.DeleteDevice, Conn.DeleteDeviceByToken and Conn.DeleteEmptyDevicesByTime, if the desired Device cannot be found in the current container
var ErrRecordNotFound = errors.New("skydb: Record not found for the specified key")
ErrRecordNotFound is returned from Get and Delete when Database cannot find the Record by the specified key
var ErrSubscriptionNotFound = errors.New("skydb: Subscription ID not found")
ErrSubscriptionNotFound is returned from GetSubscription or DeleteSubscription when the specific subscription cannot be found.
var ErrUserDuplicated = errors.New("skydb: duplicated UserID or Username")
ErrUserDuplicated is returned by Conn.CreateUser when the UserInfo to be created has the same ID/username in the current container
var ErrUserNotFound = errors.New("skydb: UserInfo ID not found")
ErrUserNotFound is returned by Conn.GetUser, Conn.UpdateUser and Conn.DeleteUser when the UserInfo's ID is not found in the current container
var ZeroTime = time.Time{}
ZeroTime represent a zero time.Time. It is used in DeleteDeviceByToken and DeleteEmptyDevicesByTime to signify a Delete without time constraint.
Functions ¶
Types ¶
type ACLLevel ¶
type ACLLevel string
ACLLevel represent the operation a user granted on a resource
const ( ReadLevel ACLLevel = "read" WriteLevel = "write" )
ReadLevel and WriteLevel is self-explanatory
type APSSetting ¶
type APSSetting struct { Alert *AppleAlert `json:"alert,omitempty"` SoundName string `json:"sound,omitempty"` ShouldBadge bool `json:"should-badge,omitempty"` ShouldSendContentAvailable bool `json:"should-send-content-available,omitempty"` }
APSSetting describes how server should send a notification to a targeted device via Apple Push Service.
type AccessModel ¶ added in v0.4.0
type AccessModel int
AccessModel indicates the type of access control model while db query.
const ( RoleBasedAccess AccessModel = iota + 1 RelationBasedAccess )
RoleBasedAccess is tranditional Role based Access Control RelationBasedAccess is Access Control determine by the user-user relation between creator and accessor
func GetAccessModel ¶ added in v0.4.0
func GetAccessModel(accessString string) AccessModel
GetAccessModel convert the string config to internal const
type AppleAlert ¶
type AppleAlert struct { Body string `json:"body,omitempty"` LocalizationKey string `json:"loc-key,omitempty"` LocalizationArgs []string `json:"loc-args,omitempty"` LaunchImage string `json:"launch-image,omitempty"` ActionLocalizationKey string `json:"action-loc-key,omitempty"` }
AppleAlert describes how a remote notification behaves and shows itself when received.
It is a subset of attributes defined in Apple's "Local and Remote Notification Programming Guide". Please follow the following link for detailed description of the attributes.
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW20
type AuthInfo ¶
AuthInfo represents the dictionary of authenticated principal ID => authData.
For example, a UserInfo connected with a Facebook account might look like this:
{ "com.facebook:46709394": { "accessToken": "someAccessToken", "expiredAt": "2015-02-26T20:05:48", "facebookID": "46709394" } }
It is assumed that the Facebook AuthProvider has "com.facebook" as provider name and "46709394" as the authenticated Facebook account ID.
type Conn ¶
type Conn interface { // CreateUser creates a new UserInfo in the container // this Conn associated to. CreateUser(userinfo *UserInfo) error // GetUser fetches the UserInfo with supplied ID in the container and // fills in the supplied UserInfo with the result. // // GetUser returns ErrUserNotFound if no UserInfo exists // for the supplied ID. GetUser(id string, userinfo *UserInfo) error // GetUserByUsernameEmail fetch the UserInfo with supplied username or email, // GetUserByUsernameEmail(username string, email string, userinfo *UserInfo) error // GetUserByPrincipalID fetches the UserInfo with supplied principal ID in the // container and fills in the supplied UserInfo with the result. // // Principal ID is an ID of an authenticated principal with such // authentication provided by AuthProvider. // // GetUserByPrincipalID returns ErrUserNotFound if no UserInfo exists // for the supplied principal ID. GetUserByPrincipalID(principalID string, userinfo *UserInfo) error // UpdateUser updates an existing UserInfo matched by the ID field. // // UpdateUser returns ErrUserNotFound if such UserInfo does not // exist in the container. UpdateUser(userinfo *UserInfo) error // QueryUser queries for UserInfo matching one of the specified emails. QueryUser(emails []string) ([]UserInfo, error) // DeleteUser removes UserInfo with the supplied ID in the container. // // DeleteUser returns ErrUserNotFound if such UserInfo does not // exist in the container. DeleteUser(id string) error // GetAsset retrieves Asset information by its name GetAsset(name string, asset *Asset) error // SaveAsset saves an Asset information into a container to // be referenced by records. SaveAsset(asset *Asset) error QueryRelation(user string, name string, direction string, config QueryConfig) []UserInfo QueryRelationCount(user string, name string, direction string) (uint64, error) AddRelation(user string, name string, targetUser string) error RemoveRelation(user string, name string, targetUser string) error GetDevice(id string, device *Device) error // QueryDevicesByUser queries the Device database which are registered // by the specified user. QueryDevicesByUser(user string) ([]Device, error) SaveDevice(device *Device) error DeleteDevice(id string) error // DeleteDeviceByToken deletes device where its Token == token and // LastRegisteredAt < t. If t == ZeroTime, LastRegisteredAt is not considered. // // If such device does not exist, ErrDeviceNotFound is returned. DeleteDeviceByToken(token string, t time.Time) error // DeleteEmptyDevicesByTime deletes device where Token is empty and // LastRegisteredAt < t. If t == ZeroTime, LastRegisteredAt is not considered. // // If such device does not exist, ErrDeviceNotFound is returned. DeleteEmptyDevicesByTime(t time.Time) error PublicDB() Database PrivateDB(userKey string) Database // Subscribe registers the specified recordEventChan to receive // RecordEvent from the Conn implementation Subscribe(recordEventChan chan RecordEvent) error Close() error }
Conn encapsulates the interface of an Skygear connection to a container.
type CountFunc ¶
type CountFunc struct {
OverallRecords bool
}
CountFunc represents a function that count number of rows matching a query
type DBHookFunc ¶
type DBHookFunc func(Database, *Record, RecordHookEvent)
DBHookFunc specifies the interface of a database hook function
type Data ¶
type Data map[string]interface{}
A Data represents a key-value object used for storing ODRecord.
type DataType ¶
type DataType uint
DataType defines the type of data that can saved into an skydb database
type Database ¶
type Database interface { // Conn returns the parent Conn of the Database Conn() Conn // ID returns the identifier of the Database. ID() string // Get fetches the Record identified by the supplied key and // writes it onto the supplied Record. // // Get returns an ErrRecordNotFound if Record identified by // the supplied key does not exist in the Database. // It also returns error if the underlying implementation // failed to read the Record. Get(id RecordID, record *Record) error GetByIDs(ids []RecordID) (*Rows, error) // Save updates the supplied Record in the Database if Record with // the same key exists, else such Record is created. // // Save returns an error if the underlying implemention failed to // create / modify the Record. Save(record *Record) error // Delete removes the Record identified by the key in the Database. // // Delete returns an ErrRecordNotFound if the Record identified by // the supplied key does not exist in the Database. // It also returns an error if the underlying implementation // failed to remove the Record. Delete(id RecordID) error // Query executes the supplied query against the Database and returns // an Rows to iterate the results. Query(query *Query) (*Rows, error) // QueryCount executes the supplied query against the Database and returns // the number of records matching the query's predicate. QueryCount(query *Query) (uint64, error) // Extend extends the Database record schema such that a record // arrived subsequently with that schema can be saved // // Extend returns an error if the specified schema conflicts with // existing schem in the Database Extend(recordType string, schema RecordSchema) error GetSubscription(key string, deviceID string, subscription *Subscription) error SaveSubscription(subscription *Subscription) error DeleteSubscription(key string, deviceID string) error GetSubscriptionsByDeviceID(deviceID string) []Subscription GetMatchingSubscriptions(record *Record) []Subscription }
Database represents a collection of record (either public or private) in a container.
type Device ¶
type Device struct { ID string Type string Token string UserInfoID string LastRegisteredAt time.Time }
Device represents a device owned by a user and ready to receive notification.
type DistanceFunc ¶
DistanceFunc represents a function that calculates distance between a user supplied location and a Record's field
func (DistanceFunc) Args ¶
func (f DistanceFunc) Args() []interface{}
Args implements the Func interface
type Driver ¶
type Driver interface {
Open(appName string, accessModel AccessModel, optionString string) (Conn, error)
}
Driver opens an connection to the underlying database.
type DriverFunc ¶
type DriverFunc func(appName string, accessModel AccessModel, optionString string) (Conn, error)
The DriverFunc type is an adapter such that an ordinary function can be used as a Driver.
func (DriverFunc) Open ¶
func (f DriverFunc) Open(appName string, accessModel AccessModel, name string) (Conn, error)
Open returns a Conn by calling the DriverFunc itself.
type Expression ¶
type Expression struct { Type ExpressionType Value interface{} }
An Expression represents value to be compared against.
func (Expression) IsEmpty ¶ added in v0.3.0
func (expr Expression) IsEmpty() bool
func (Expression) IsKeyPath ¶
func (expr Expression) IsKeyPath() bool
func (Expression) IsLiteralArray ¶
func (expr Expression) IsLiteralArray() bool
func (Expression) IsLiteralMap ¶
func (expr Expression) IsLiteralMap() bool
func (Expression) IsLiteralString ¶
func (expr Expression) IsLiteralString() bool
type ExpressionType ¶
type ExpressionType int
ExpressionType is the type of an Expression.
const ( Literal ExpressionType = iota + 1 KeyPath Function )
A list of ExpressionTypes.
type FieldType ¶
type FieldType struct { Type DataType ReferenceType string // used only by TypeReference Expression Expression // used by Computed Keys }
FieldType represents the kind of data living within a field of a RecordSchema.
type Func ¶
type Func interface {
Args() []interface{}
}
Func is a marker interface to denote a type being a function in skydb.
skydb's function receives zero or more arguments and returns a DataType as a result. Result data type is currently omitted in this interface since skygear doesn't use it internally yet. In the future it can be utilized to provide more extensive type checking at handler level.
type Location ¶
type Location [2]float64
Location represent a point of geometry.
It being an array of two floats is intended to provide no-copy conversion between paulmach/go.geo.Point.
type MemoryRows ¶
MemoryRows is a native implementation of RowIter. Can be used in test not support cursor.
func NewMemoryRows ¶
func NewMemoryRows(records []Record) *MemoryRows
func (*MemoryRows) Close ¶
func (rs *MemoryRows) Close() error
func (*MemoryRows) Next ¶
func (rs *MemoryRows) Next(record *Record) error
func (*MemoryRows) OverallRecordCount ¶
func (rs *MemoryRows) OverallRecordCount() *uint64
type NotificationInfo ¶
type NotificationInfo struct {
APS APSSetting `json:"aps,omitempty"`
}
NotificationInfo describes how server should send a notification to a target devices via a push service. Currently only APS is supported.
type Operator ¶
type Operator int
Operator denotes how the result of a predicate is determined from its subpredicates or subexpressions.
const ( And Operator = iota + 1 Or Not Equal GreaterThan LessThan GreaterThanOrEqual LessThanOrEqual NotEqual Like ILike In Functional )
A list of Operator.
func (Operator) IsBinary ¶
IsBinary checks whether the Operator determines the result of a predicate by comparing two subexpressions.
func (Operator) IsCompound ¶
IsCompound checks whether the Operator is a compound operator, meaning the operator combine the results of other subpredicates.
type Predicate ¶
type Predicate struct { Operator Operator Children []interface{} }
Predicate is a representation of used in query for filtering records.
func (Predicate) GetExpressions ¶
func (p Predicate) GetExpressions() (ps []Expression)
GetExpressions returns Predicate.Children as []Expression.
This method is only valid when Operator is binary operator. Caller is responsible to check for this preconditions. Otherwise the method will panic.
func (Predicate) GetSubPredicates ¶
GetSubPredicates returns Predicate.Children as []Predicate.
This method is only valid when Operator is either And, Or and Not. Caller is responsible to check for this preconditions. Otherwise the method will panic.
type Query ¶
type Query struct { Type string Predicate Predicate Sorts []Sort ReadableBy string ComputedKeys map[string]Expression DesiredKeys []string GetCount bool Limit *uint64 Offset uint64 }
Query specifies the type, predicate and sorting order of Database query. ReadableBy is a temp solution for ACL before a full predicate implemented.
type QueryConfig ¶ added in v0.3.0
QueryConfig provides optional parameters for queries. result is unlimited if Limit=0
type Record ¶
type Record struct { ID RecordID DatabaseID string `json:"-"` OwnerID string CreatedAt time.Time CreatorID string UpdatedAt time.Time UpdaterID string ACL RecordACL Data Data Transient Data `json:"-"` }
Record is the primary entity of storage in Skygear.
type RecordACL ¶
type RecordACL []RecordACLEntry
RecordACL is a list of ACL entries defining access control for a record
func NewRecordACL ¶
func NewRecordACL(entries []RecordACLEntry) RecordACL
NewRecordACL returns a new RecordACL
func (*RecordACL) InitFromJSON ¶
InitFromJSON initializes a RecordACL
type RecordACLEntry ¶
type RecordACLEntry struct { Relation string `json:"relation"` Level ACLLevel `json:"level"` UserID string `json:"user_id,omitempty"` }
RecordACLEntry grants access to a record by relation or by user_id
func NewRecordACLEntryDirect ¶
func NewRecordACLEntryDirect(userID string, level ACLLevel) RecordACLEntry
NewRecordACLEntryDirect returns an ACE for a specific user
func NewRecordACLEntryRelation ¶
func NewRecordACLEntryRelation(relation string, level ACLLevel) RecordACLEntry
NewRecordACLEntryRelation returns an ACE on relation
func (*RecordACLEntry) InitFromJSON ¶
func (entry *RecordACLEntry) InitFromJSON(i interface{}) error
InitFromJSON initializes a RecordACLEntry from a unmarshalled JSON of access control definition
type RecordEvent ¶
type RecordEvent struct { Record *Record Event RecordHookEvent }
RecordEvent describes a change event on Record which is either Created, Updated or Deleted.
For RecordCreated or RecordUpdated event, Record is the newly created / updated Record. For RecordDeleted, Record is the Record being deleted.
type RecordHookEvent ¶
type RecordHookEvent int
RecordHookEvent indicates the type of record event that triggered the hook
const ( RecordCreated RecordHookEvent = iota + 1 RecordUpdated RecordDeleted )
See the definition of RecordHookEvent
type RecordID ¶
RecordID identifies an unique record in a Database
func NewRecordID ¶
NewRecordID returns a new RecordID
func (RecordID) MarshalText ¶
MarshalText implements the encoding.TextUnmarshaler interface.
func (*RecordID) UnmarshalText ¶
UnmarshalText implements the encoding.TextMarshaler interface.
type RecordSchema ¶
RecordSchema is a mapping of record key to its value's data type or reference
type Rows ¶
type Rows struct {
// contains filtered or unexported fields
}
Rows implements a scanner-like interface for easy iteration on a result set returned from a query
func NewRows ¶
NewRows creates a new Rows.
Driver implementators are expected to call this method with their implementation of RowsIter to return a Rows from Database.Query.
func (*Rows) Err ¶
Err returns the last error encountered during Scan.
NOTE: It is not an error if the underlying result set is exhausted.
func (*Rows) OverallRecordCount ¶
OverallRecordCount returns the number of matching records in the database if this resultset contains any rows.
type RowsIter ¶
type RowsIter interface { // Close closes the rows iterator Close() error // Next populates the next Record in the current rows iterator into // the provided record. // // Next should return io.EOF when there are no more rows Next(record *Record) error OverallRecordCount() *uint64 }
RowsIter is an iterator on results returned by execution of a query.
type Sequence ¶
type Sequence struct{}
Sequence is a bogus data type for creating a sequence field via JIT schema migration
type Sort ¶
Sort specifies the order of a collection of Records returned from a Query.
Record order can be sorted w.r.t. a record field or a value returned from a predefined function.
type SortOrder ¶
type SortOrder int
SortOrder denotes an the order of Records returned from a Query.
type Subscription ¶
type Subscription struct { ID string `json:"id"` Type string `json:"type"` DeviceID string `json:"device_id"` NotificationInfo *NotificationInfo `json:"notification_info,omitempty"` Query Query `json:"query"` }
Subscription represents a device's subscription of notification triggered by changes of results from a query.
type TxDatabase ¶
type TxDatabase interface { // Begin opens a transaction for the current Database. // // Calling Begin on an already Begin'ed Database returns ErrDatabaseTxDidBegin. Begin() error // Commit saves all the changes made to Database after Begin atomically. Commit() error // Rollbacks discards all the changes made to Database after Begin. Rollback() error }
TxDatabase defines the methods for a Database that supports transaction.
A Begin'ed transaction must end with a call to Commit or Rollback. After that, all opertions on Database will return ErrDatabaseTxDone.
NOTE(limouren): The interface is not Database specific, but currently only Database supports it.
type UserInfo ¶
type UserInfo struct { ID string `json:"_id"` Username string `json:"username,omitempty"` Email string `json:"email,omitempty"` HashedPassword []byte `json:"password,omitempty"` Auth AuthInfo `json:"auth,omitempty"` // auth data for alternative methods }
UserInfo contains a user's information for authentication purpose
func NewAnonymousUserInfo ¶
func NewAnonymousUserInfo() UserInfo
NewAnonymousUserInfo returns an anonymous UserInfo, which has no Email and Password.
func NewProvidedAuthUserInfo ¶
NewProvidedAuthUserInfo returns an UserInfo provided by a AuthProvider, which has no Email and Password.
func NewUserInfo ¶
NewUserInfo returns a new UserInfo with specified username, email and password. An UUID4 ID will be generated by the system as unique identifier
func (*UserInfo) GetProvidedAuthData ¶
GetProvidedAuthData gets the auth data for the specified principal.
func (UserInfo) IsSamePassword ¶
IsSamePassword determines whether the specified password is the same password as where the HashedPassword is generated from
func (*UserInfo) RemoveProvidedAuthData ¶
RemoveProvidedAuthData remove the auth data for the specified principal.
func (*UserInfo) SetPassword ¶
SetPassword sets the HashedPassword with the password specified
func (*UserInfo) SetProvidedAuthData ¶
SetProvidedAuthData sets the auth data to the specified principal.
type UserRelationFunc ¶
type UserRelationFunc struct { KeyPath string RelationName string RelationDirection string User string }
UserRelationFunc represents a function that is used to evaulate whether a record satisfy certain user-based relation
func (UserRelationFunc) Args ¶
func (f UserRelationFunc) Args() []interface{}
Args implements the Func interface