diff --git a/error.go b/error.go index bd8358295c1b472bd8bd6b934b880b8e8b7c9d79..9ddd53227bec7900334b2dfe8532ce3a135006e8 100644 --- a/error.go +++ b/error.go @@ -1,25 +1,23 @@ -/* - Copyright (c) 2012-2014 José Carlos Nieto, https://menteslibres.net/xiam - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ +// Copyright (c) 2012-2014 José Carlos Nieto, https://menteslibres.net/xiam +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. package db @@ -27,7 +25,7 @@ import ( "errors" ) -// Application error messages. +// Shared error messages. var ( ErrExpectingPointer = errors.New(`Argument must be an address.`) ErrExpectingSlicePointer = errors.New(`Argument must be a slice address.`) @@ -46,7 +44,7 @@ var ( ErrUnsupported = errors.New(`This action is currently unsupported on this database.`) ErrQueryIsPending = errors.New(`Can't execute this instruction while the result set is still open.`) ErrUnsupportedDestination = errors.New(`Unsupported destination type.`) - - // Deprecated but kept for backwards compatibility. See: https://github.com/upper/db/issues/18 - ErrCollectionDoesNotExists = ErrCollectionDoesNotExist ) + +// Deprecated but kept for backwards compatibility. See: https://github.com/upper/db/issues/18 +var ErrCollectionDoesNotExists = ErrCollectionDoesNotExist diff --git a/main_test.go b/main_test.go index 9c3f84d4b36ade56e1b4b1d83176d042c837a096..5242221026433188cd547e318acfc62fc2f2416c 100644 --- a/main_test.go +++ b/main_test.go @@ -1,3 +1,24 @@ +// Copyright (c) 2012-2014 José Carlos Nieto, https://menteslibres.net/xiam +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + package db_test import ( diff --git a/wrapper.go b/wrapper.go index d199580f2f53eb090bbfe8e4d3bfbbb3a6625cbb..443fa04f96043755ac02b033a59acd636b8f9a60 100644 --- a/wrapper.go +++ b/wrapper.go @@ -1,25 +1,23 @@ -/* - Copyright (c) 2012-2014 José Carlos Nieto, https://menteslibres.net/xiam - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ +// Copyright (c) 2012-2014 José Carlos Nieto, https://menteslibres.net/xiam +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. package db @@ -28,34 +26,35 @@ import ( "reflect" ) -// Registered wrappers. +// This map holds a copy of all registered adapters. var wrappers = make(map[string]Database) -// Registers a database wrapper with a unique name. -func Register(name string, driver Database) { +// The db.Register() function is provided for database adapters. Using +// db.Register() an adapter can make itself available by the provided name. +// The adapter name must not be an empty string and the driver must not be nil, +// otherwise db.Register() will panic. +func Register(name string, adapter Database) { - if name == "" { - panic("Missing wrapper name.") + if name == `` { + panic(`Missing adapter name.`) } if _, ok := wrappers[name]; ok != false { - panic("Register called twice for driver " + name) + panic(`db.Register() called twice for adapter: ` + name) } - wrappers[name] = driver + wrappers[name] = adapter } -// Configures a connection to a database using the named adapter and the given +// Configures a database sessions using the given adapter and the given // settings. func Open(name string, settings Settings) (Database, error) { driver, ok := wrappers[name] if ok == false { // Using panic instead of returning error because attemping to use an - // nonexistent adapter will never result in a successful connection, - // therefore should be considered a developer's mistake and must be catched - // at compilation time. - panic(fmt.Sprintf("Open: Unknown adapter %s. (see: https://upper.io/db#database-adapters)", name)) + // nonexistent adapter will never result in a successful connection. + panic(fmt.Sprintf(`Open: Unknown adapter %s. (see: https://upper.io/db#database-adapters)`, name)) } // Creating a new connection everytime Open() is called. @@ -63,8 +62,7 @@ func Open(name string, settings Settings) (Database, error) { newAdapter := reflect.New(driverType).Interface().(Database) // Setting up the connection. - err := newAdapter.Setup(settings) - if err != nil { + if err := newAdapter.Setup(settings); err != nil { return nil, err }