Plugin:MirLua/Module/m database: Difference between revisions
Jump to navigation
Jump to search
(double pipes) |
mNo edit summary |
||
Line 10: | Line 10: | ||
== Contacts == | == Contacts == | ||
=== | === Contacts === | ||
Iterator for list of contacts. | Iterator for list of contacts. | ||
;Parameters | ;Parameters | ||
Line 21: | Line 21: | ||
;Example | ;Example | ||
{{Content:MirLua/Example|code= | {{Content:MirLua/Example|code= | ||
for hContact in db. | for hContact in db.Contacts('JABBER_1') do | ||
print(db.GetSetting(hContact, 'JABBER_1', 'Nick')) | print(db.GetSetting(hContact, 'JABBER_1', 'Nick')) | ||
end | end | ||
Line 40: | Line 40: | ||
{{Content:MirLua/Example|code=db.GetEventCount(hContact)}} | {{Content:MirLua/Example|code=db.GetEventCount(hContact)}} | ||
=== | === Events === | ||
Iterator for contact's event list from the first to the last. | Iterator for contact's event list from the first to the last. | ||
;Parameters | ;Parameters | ||
Line 50: | Line 50: | ||
: Returns event number. The list ends in element with '''nil''' value. | : Returns event number. The list ends in element with '''nil''' value. | ||
;Example | ;Example | ||
{{Content:MirLua/Example|code=for hEvent in db. | {{Content:MirLua/Example|code=for hEvent in db.Events(hContact) do | ||
local event = totable(hEvent, "DBEVENTINFO") | local event = totable(hEvent, "DBEVENTINFO") | ||
print(event.Timestamp, event.Blob) | print(event.Timestamp, event.Blob) | ||
Line 56: | Line 56: | ||
}} | }} | ||
=== | === EventsFromEnd === | ||
Iterator for contact's event list from the last to the first. | Iterator for contact's event list from the last to the first. | ||
;Parameters | ;Parameters | ||
Line 67: | Line 67: | ||
;Example | ;Example | ||
{{Content:MirLua/Example|code= | {{Content:MirLua/Example|code= | ||
for hEvent in db. | for hEvent in db.EventsFromEnd(hContact) do | ||
local event = totable(hEvent, "DBEVENTINFO") | local event = totable(hEvent, "DBEVENTINFO") | ||
print(event.Timestamp, event.Blob) | print(event.Timestamp, event.Blob) | ||
Line 96: | Line 96: | ||
{{Content:MirLua/Example|code=db.GetSetting(nil, 'test', 'some')}} | {{Content:MirLua/Example|code=db.GetSetting(nil, 'test', 'some')}} | ||
=== | === Settings === | ||
Iterator for module (group of settings). | Iterator for module (group of settings). | ||
;Parameters | ;Parameters | ||
Line 110: | Line 110: | ||
;Example | ;Example | ||
{{Content:MirLua/Example|code= | {{Content:MirLua/Example|code= | ||
for setting in db. | for setting in db.Settings(nil, 'CList') do | ||
local message = string.format("%s/%s = ", 'CList', setting, ...) | local message = string.format("%s/%s = ", 'CList', setting, ...) | ||
.. db.GetSetting(nil, 'CList', setting) | .. db.GetSetting(nil, 'CList', setting) |
Revision as of 21:56, 31 December 2015
Allows you to access data and contacts in user profile database.
Include module: local db = require('m_database')
<translate> Note</translate>
Parameters written in bold italics are obligatory.
Parameters written in bold italics are obligatory.
Contacts
Contacts
Iterator for list of contacts.
- Parameters
- name
- Type: string
- Protocol name.
- Result
- Type: number
- Returns contact number. The list ends in element with nil value.
- Example
for hContact in db.Contacts('JABBER_1') do
print(db.GetSetting(hContact, 'JABBER_1', 'Nick'))
end
Events
GetEventCount
Number of events for a contact.
- Parameters
- hContact
- Type: number
- Contact number.
- Result
- Type: number
- Returns number of events.
- Example
db.GetEventCount(hContact)
Events
Iterator for contact's event list from the first to the last.
- Parameters
- hContact
- Type: number
- Contact number.
- Result
- Type: number
- Returns event number. The list ends in element with nil value.
- Example
for hEvent in db.Events(hContact) do
local event = totable(hEvent, "DBEVENTINFO")
print(event.Timestamp, event.Blob)
end
EventsFromEnd
Iterator for contact's event list from the last to the first.
- Parameters
- hContact
- Type: number
- Contact number.
- Result
- Type: number
- Returns event number. The list ends in element with nil value.
- Example
for hEvent in db.EventsFromEnd(hContact) do
local event = totable(hEvent, "DBEVENTINFO")
print(event.Timestamp, event.Blob)
end
Settings
GetSetting
Returns value of a setting.
- Parameters
- hContact
- Type: number
- Contact number or nil.
- module
- Type: string
- Module name.
- setting
- Type: string
- Setting name.
- value
- Type: number, string
- Default value.
- Result
- Type: number
- Returns value of a setting or default value or nil.
- Example
db.GetSetting(nil, 'test', 'some')
Settings
Iterator for module (group of settings).
- Parameters
- hContact
- Type: number
- Contact number or nil.
- module
- Type: string
- Module name.
- Result
- Type: number
- Returns module name. The list ends in element with nil value.
- Example
for setting in db.Settings(nil, 'CList') do
local message = string.format("%s/%s = ", 'CList', setting, ...)
.. db.GetSetting(nil, 'CList', setting)
print(message)
end
WriteSetting
Saves a value to database.
- Parameters
- hContact
- Type: number
- Contact number or nil.
- module
- Type: string
- Module name.
- setting
- Type: string
- Setting name.
- Result
- Type: boolean
- Returns true in case of success, else false.
- Example
db.WriteSetting(nil, 'test', 'some', true)
DeleteSetting
Deletes a setting.
- Parameters
- hContact
- Type: number
- Contact number or nil.
- module
- Type: string
- Module name.
- setting
- Type: string
- Setting name.
- Result
- Type: boolean
- Returns true in case of success, else false.
- Example
db.DeleteSetting(nil, 'test', 'some')
DeleteModule
Deletes a module (group of settings).
- Parameters
- hContact
- Type: number
- Contact number or nil.
- module
- Type: string
- Module name.
- Result
- Type: boolean
- Returns true in case of success, else false.
- Example
db.DeleteModule(nil, 'test')