Skip to content

Commit 24283f6

Browse files
authored
Merge pull request #208 from fnc12/dev
Dev to master for 1.3
2 parents 8ee3d47 + 0803e96 commit 24283f6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+6401
-2178
lines changed

.travis.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ script:
1717
- clang -c sqlite-amalgamation-3190300/sqlite3.c -o sqlite.static
1818
- clang++ -std=c++1y tests/tests.cpp sqlite.static -I include/ -I sqlite_amalgamation/ -ldl -lpthread -stdlib=libc++ -o tests.out
1919
- ./tests.out
20+
- clang++ -std=c++1y tests/tests.cpp sqlite.static -I include/ -I sqlite_amalgamation/ -ldl -lpthread -stdlib=libc++ -D SQLITE_ORM_OMITS_CODECVT -o tests_without_codecvt.out
21+
- ./tests_without_codecvt.out
2022
- clang++ -std=c++1y tests/static_tests.cpp sqlite.static -I include/ -I sqlite_amalgamation/ -ldl -lpthread -stdlib=libc++ -o static_tests.out
2123
- ./static_tests.out
2224
- clang++ -std=c++1y examples/core_functions.cpp sqlite.static -I include/ -I sqlite_amalgamation/ -ldl -lpthread -o a.out
@@ -49,8 +51,6 @@ script:
4951
- ./a.out
5052
- clang++ -std=c++1y examples/blob.cpp sqlite.static -I include/ -I sqlite_amalgamation/ -ldl -lpthread -o a.out
5153
- ./a.out
52-
- clang++ -std=c++1y examples/private_class_members.cpp sqlite.static -I include/ -I sqlite_amalgamation/ -ldl -lpthread -o a.out
53-
- ./a.out
5454
- clang++ -std=c++1y examples/foreign_key.cpp sqlite.static -I include/ -I sqlite_amalgamation/ -ldl -lpthread -o a.out
5555
- ./a.out
5656
- clang++ -std=c++1y examples/index.cpp sqlite.static -I include/ -I sqlite_amalgamation/ -ldl -lpthread -o a.out
@@ -69,3 +69,13 @@ script:
6969
- ./a.out
7070
- clang++ -std=c++1y examples/union.cpp sqlite.static -I include/ -I sqlite_amalgamation/ -ldl -lpthread -o a.out
7171
- ./a.out
72+
- clang++ -std=c++1y examples/subquery.cpp sqlite.static -I include/ -I sqlite_amalgamation/ -ldl -lpthread -o a.out
73+
- ./a.out
74+
- clang++ -std=c++1y examples/having.cpp sqlite.static -I include/ -I sqlite_amalgamation/ -ldl -lpthread -o a.out
75+
- ./a.out
76+
- clang++ -std=c++1y examples/exists.cpp sqlite.static -I include/ -I sqlite_amalgamation/ -ldl -lpthread -o a.out
77+
- ./a.out
78+
- clang++ -std=c++1y examples/except_intersection.cpp sqlite.static -I include/ -I sqlite_amalgamation/ -ldl -lpthread -o a.out
79+
- ./a.out
80+
- clang++ -std=c++1y examples/custom_aliases.cpp sqlite.static -I include/ -I sqlite_amalgamation/ -ldl -lpthread -o a.out
81+
- ./a.out

CMakeLists.txt

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,55 @@ cmake_minimum_required (VERSION 3.2)
22
set(CMAKE_CXX_STANDARD 14)
33
set(CMAKE_CXX_STANDARD_REQUIRED ON)
44

5-
project(sqlite_orm)
5+
# PACKAGE_VERSION is used by cpack scripts currently
6+
# Both sqlite_orm_VERSION and PACKAGE_VERSION should be the same for now
7+
8+
set(sqlite_orm_VERSION "1.3.0")
9+
set(PACKAGE_VERSION ${sqlite_orm_VERSION})
10+
11+
project("sqlite_orm" VERSION ${PACKAGE_VERSION})
12+
13+
message(STATUS "Configuring ${CMAKE_PROJECT_NAME} ${sqlite_orm_VERSION}")
14+
15+
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_CURRENT_SOURCE_DIR}/build/cmake")
16+
17+
# Build time options are defined here
18+
include(DefineInstallationPaths)
19+
20+
# Generate the SqliteOrmConfig.cmake module
21+
include(GenerateConfigModule)
22+
23+
set(ProjectName "SqliteOrm")
624

725
option(SqliteOrm_BuildTests "Build sqlite_orm unit tests" ON)
826

927
set(SqliteOrm_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/include")
1028
add_library(sqlite_orm INTERFACE)
11-
target_include_directories(sqlite_orm INTERFACE include)
29+
30+
target_sources(sqlite_orm INTERFACE
31+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/sqlite_orm/sqlite_orm.h>
32+
$<INSTALL_INTERFACE:include/sqlite_orm/sqlite_orm.h>)
33+
34+
target_include_directories(sqlite_orm INTERFACE
35+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
36+
$<INSTALL_INTERFACE:include>)
37+
38+
include(ucm)
39+
40+
if (MSVC)
41+
string(REGEX REPLACE "/RTC(su|[1su])" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
42+
string(REGEX REPLACE "/RTC(su|[1su])" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
43+
string(REGEX REPLACE "/RTC(su|[1su])" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
44+
add_compile_options(/EHsc)
45+
46+
if ("${CMAKE_GENERATOR}" MATCHES "(Win64|x64)")
47+
message(STATUS "Add /bigobj flag to compiler")
48+
add_compile_options(/bigobj)
49+
endif()
50+
endif()
51+
52+
ucm_print_flags()
53+
message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
1254

1355
# Tests
1456
include(CTest)
@@ -19,3 +61,18 @@ endif()
1961

2062
add_subdirectory(examples)
2163

64+
install(TARGETS sqlite_orm EXPORT "${ProjectName}Targets"
65+
INCLUDES DESTINATION "${INCLUDE_INSTALL_DIR}" COMPONENT Development
66+
PUBLIC_HEADER DESTINATION "${INCLUDE_INSTALL_DIR}" COMPONENT Development)
67+
68+
install(FILES "include/sqlite_orm/sqlite_orm.h"
69+
DESTINATION "${INCLUDE_INSTALL_DIR}" COMPONENT Development)
70+
71+
export(EXPORT "${ProjectName}Targets"
72+
FILE "${CMAKE_CURRENT_BINARY_DIR}/${ProjectName}/${ProjectName}Targets.cmake"
73+
NAMESPACE "sqlite_orm::")
74+
75+
install(EXPORT "${ProjectName}Targets"
76+
FILE "${ProjectName}Targets.cmake"
77+
NAMESPACE "sqlite_orm::"
78+
DESTINATION "${CMAKE_INSTALL_DIR}/sqlite_orm")

README.md

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,19 @@
33
</p>
44

55
[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)
6-
[![Build Status](https://travis-ci.org/fnc12/sqlite_orm.svg?branch=master)](https://travis-ci.org/fnc12/sqlite_orm)
76
[![Donate using PayPal](https://img.shields.io/badge/donate-PayPal-brightgreen.svg)](https://paypal.me/fnc12)
7+
[![Twitter URL](https://img.shields.io/twitter/url/https/twitter.com/fold_left.svg?style=social&label=Follow%20%40sqlite_orm)](https://twitter.com/sqlite_orm)
8+
89

910
# SQLite ORM
1011
SQLite ORM light header only library for modern C++
1112

13+
# Status
14+
| Branch | Travis | Appveyor | Coverity Scan | codecov.io | Website |
15+
| :----- | :----- | :------- | :------------ | :--------- | :------ |
16+
| [`master`](https://github.com/fcn12/sqlite_orm/tree/master) | [![Build Status](https://travis-ci.org/fnc12/sqlite_orm.svg?branch=master)](https://travis-ci.org/fcn12/sqlite_orm) | [![Build status](https://ci.appveyor.com/api/projects/status/github/fnc12/sqlite_orm?branch=master&svg=true)](https://ci.appveyor.com/project/fnc12/sqlite-orm/history) | | | [![Website](https://img.shields.io/badge/official-website-brightgreen.svg)](https://github.com/fcn12/sqlite_orm/) |
17+
| [`dev`](https://github.com/fcn12/sqlite_orm/tree/dev) | [![Build Status](https://travis-ci.org/fnc12/sqlite_orm.svg?branch=dev)](https://travis-ci.org/fcn12/sqlite_orm) | [![Build status](https://ci.appveyor.com/api/projects/status/github/fnc12/sqlite_orm?branch=dev&svg=true)](https://ci.appveyor.com/project/fnc12/sqlite-orm/history) | | | [![Website](https://img.shields.io/badge/official-website-brightgreen.svg)](https://github.com/fcn12/sqlite_orm/tree/dev) |
18+
1219
# Advantages
1320

1421
* **No raw string queries**
@@ -17,6 +24,7 @@ SQLite ORM light header only library for modern C++
1724
* **Built with modern C++14 features (no macros and external scripts)**
1825
* **CRUD support**
1926
* **Pure select query support**
27+
* **UNION, EXCEPT and INTERSECT support**
2028
* **STL compatible**
2129
* **Custom types binding support**
2230
* **BLOB support** - maps to `std::vector<char>` or one can bind your custom type
@@ -47,7 +55,7 @@ struct User{
4755
std::string firstName;
4856
std::string lastName;
4957
int birthDate;
50-
std::shared_ptr<std::string> imageUrl;
58+
std::unique_ptr<std::string> imageUrl;
5159
int typeId;
5260
};
5361

@@ -93,7 +101,7 @@ More details about making storage can be found in [tutorial](https://github.com/
93101
Let's create and insert new `User` into database. First we need to create a `User` object with any id and call `insert` function. It will return id of just created user or throw exception if something goes wrong.
94102

95103
```c++
96-
User user{-1, "Jonh", "Doe", 664416000, std::make_shared<std::string>("url_to_heaven"), 3 };
104+
User user{-1, "Jonh", "Doe", 664416000, std::make_unique<std::string>("url_to_heaven"), 3 };
97105

98106
auto insertedId = storage.insert(user);
99107
cout << "insertedId = " << insertedId << endl; // insertedId = 8
@@ -118,17 +126,17 @@ try{
118126
}
119127
```
120128

121-
Probably you may not like throwing exceptions. Me too. Exception `std::system_error` is thrown because return type in `get` function is not nullable. You can use alternative version `get_no_throw` which returns `std::shared_ptr` and doesn't throw `not_found_exception` if nothing found - just returns `nullptr`.
129+
Probably you may not like throwing exceptions. Me too. Exception `std::system_error` is thrown because return type in `get` function is not nullable. You can use alternative version `get_pointer` which returns `std::unique_ptr` and doesn't throw `not_found_exception` if nothing found - just returns `nullptr`.
122130

123131
```c++
124-
if(auto user = storage.get_no_throw<User>(insertedId)){
132+
if(auto user = storage.get_pointer<User>(insertedId)){
125133
cout << "user = " << user->firstName << " " << user->lastName << endl;
126134
}else{
127135
cout << "no user with id " << insertedId << endl;
128136
}
129137
```
130138

131-
`std::shared_ptr` is used as optional in `sqlite_orm`. Of course there is class optional in C++14 located at `std::experimental::optional`. But we don't want to use it until it is `experimental`.
139+
`std::unique_ptr` is used as optional in `sqlite_orm`. Of course there is class optional in C++14 located at `std::experimental::optional`. But we don't want to use it until it is `experimental`.
132140

133141
We can also update our user. It updates row by id provided in `user` object and sets all other non `primary_key` fields to values stored in the passed `user` object. So you can just assign members to `user` object you want and call `update`
134142

@@ -180,7 +188,7 @@ for(auto &user : storage.iterate<User>()) {
180188

181189
`iterate` member function returns adapter object that has `begin` and `end` member functions returning iterators that fetch object on dereference operator call.
182190

183-
CRUD functions `get`, `get_no_throw`, `remove`, `update` (not `insert`) work only if your type has a primary key column. If you try to `get` an object that is mapped to your storage but has no primary key column a `std::system_error` will be thrown cause `sqlite_orm` cannot detect an id. If you want to know how to perform a storage without primary key take a look at `date_time.cpp` example in `examples` folder.
191+
CRUD functions `get`, `get_pointer`, `remove`, `update` (not `insert`) work only if your type has a primary key column. If you try to `get` an object that is mapped to your storage but has no primary key column a `std::system_error` will be thrown cause `sqlite_orm` cannot detect an id. If you want to know how to perform a storage without primary key take a look at `date_time.cpp` example in `examples` folder.
184192

185193
# Aggregate Functions
186194

@@ -215,21 +223,21 @@ cout << "concatedUserIdWithDashes = " << concatedUserIdWithDashes << endl;
215223

216224
// SELECT MAX(id) FROM users
217225
if(auto maxId = storage.max(&User::id)){
218-
cout << "maxId = " << *maxId <<endl; // maxId = 12 (maxId is std::shared_ptr<int>)
226+
cout << "maxId = " << *maxId <<endl; // maxId = 12 (maxId is std::unique_ptr<int>)
219227
}else{
220228
cout << "maxId is null" << endl;
221229
}
222230

223231
// SELECT MAX(first_name) FROM users
224232
if(auto maxFirstName = storage.max(&User::firstName)){
225-
cout << "maxFirstName = " << *maxFirstName << endl; // maxFirstName = Jonh (maxFirstName is std::shared_ptr<std::string>)
233+
cout << "maxFirstName = " << *maxFirstName << endl; // maxFirstName = Jonh (maxFirstName is std::unique_ptr<std::string>)
226234
}else{
227235
cout << "maxFirstName is null" << endl;
228236
}
229237

230238
// SELECT MIN(id) FROM users
231239
if(auto minId = storage.min(&User::id)){
232-
cout << "minId = " << *minId << endl; // minId = 1 (minId is std::shared_ptr<int>)
240+
cout << "minId = " << *minId << endl; // minId = 1 (minId is std::unique_ptr<int>)
233241
}else{
234242
cout << "minId is null" << endl;
235243
}
@@ -242,7 +250,7 @@ if(auto minLastName = storage.min(&User::lastName)){
242250
}
243251

244252
// SELECT SUM(id) FROM users
245-
if(auto sumId = storage.sum(&User::id)){ // sumId is std::shared_ptr<int>
253+
if(auto sumId = storage.sum(&User::id)){ // sumId is std::unique_ptr<int>
246254
cout << "sumId = " << *sumId << endl;
247255
}else{
248256
cout << "sumId is null" << endl;

TODO.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@
55
* `FOREIGN KEY` - sync_schema fk comparison and ability of two tables to have fk to each other
66
* rest of core functions(https://sqlite.org/lang_corefunc.html)
77
* `CASE`
8-
* `HAVING`
9-
* `EXISTS`
108
* asterisk in raw select: `SELECT rowid, * FROM table`
119
* `ATTACH`
1210
* blob incremental I/O https://sqlite.org/c3ref/blob_open.html
1311
* reusing of prepared statements - useful for query optimisation
14-
* subselect
12+
* explicit FROM for subqueries in FROM argument
1513
* backup API https://www.sqlite.org/backup.html
1614
* busy handler https://sqlite.org/c3ref/busy_handler.html
1715
* CAST https://sqlite.org/lang_expr.html#castexpr
1816
* CREATE VIEW and other view operations https://sqlite.org/lang_createview.html
1917
* triggers
18+
* query static check for correct order (e.g. `GROUP BY` after `WHERE`)
19+
* column alias
20+
* `FULL OUTER JOIN`
21+
* `WINDOW`
22+
* `UPSERT` https://www.sqlite.org/lang_UPSERT.html
2023

2124
Please feel free to add any feature that isn't listed here and not implemented yet.

appveyor.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright (c) 2012-2019 Sebastien Rombauts ([email protected])
2+
3+
# build format
4+
version: "{build}"
5+
6+
# scripts that run after cloning repository
7+
install:
8+
- git submodule update --init --recursive
9+
10+
image:
11+
- Visual Studio 2017
12+
13+
# configurations to add to build matrix
14+
# TODO: MinGW Makefiles and MSYS Makefiles
15+
configuration:
16+
- Debug
17+
- Release
18+
19+
environment:
20+
matrix:
21+
- arch: Win32
22+
- arch: Win64
23+
24+
init:
25+
- echo %APPVEYOR_BUILD_WORKER_IMAGE% - %configuration% - %arch%
26+
- if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2017" (set vs=Visual Studio 15 2017)
27+
- if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2015" (set vs=Visual Studio 14 2015)
28+
- if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2013" (set vs=Visual Studio 12 2013)
29+
- if "%arch%"=="Win64" (set generator="%vs% Win64")
30+
- if "%arch%"=="Win32" (set generator="%vs%")
31+
- echo %generator%
32+
33+
# scripts to run before build
34+
before_build:
35+
- mkdir compile
36+
- cd compile
37+
- cmake -DSqliteOrm_BuildTests=ON .. -G %generator%
38+
39+
# build examples, and run tests (ie make & make test)
40+
build_script:
41+
- cmake --build . --config %configuration%
42+
- ctest --output-on-failure --build-config %configuration%
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Define the default install paths
2+
set(BIN_INSTALL_DIR "bin" CACHE PATH "The binary install dir (default: bin)")
3+
set(LIB_INSTALL_DIR "lib${LIB_SUFFIX}" CACHE PATH "The library install dir (default: lib${LIB_SUFFIX})")
4+
set(INCLUDE_INSTALL_DIR "include" CACHE PATH "The library install dir (default: include)")
5+
set(CMAKE_INSTALL_DIR "lib/cmake" CACHE PATH "The subdirectory to install cmake config files (default: cmake)")
6+
set(PKGCONFIG_INSTALL_DIR "lib/pkgconfig" CACHE PATH "The subdirectory to install pkgconfig config files (default: lib/pkgconfig)")
7+
set(DOC_INSTALL_DIR "share/doc" CACHE PATH "The subdirectory to install documentation files (default: share/doc)")
8+
set(prefix "${CMAKE_INSTALL_PREFIX}")
9+
set(exec_prefix "${CMAKE_INSTALL_PREFIX}/bin")
10+
set(libdir "${CMAKE_INSTALL_PREFIX}/lib")
11+
set(includedir "${CMAKE_INSTALL_PREFIX}/include")
12+
set(cmakedir "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DIR}")
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
include(CMakePackageConfigHelpers)
2+
3+
set(PACKAGE_INCLUDE_INSTALL_DIR "${includedir}/sqlite_orm")
4+
set(PACKAGE_CMAKE_INSTALL_DIR "${cmakedir}/sqlite_orm")
5+
6+
# In CYGWIN enviroment below commands does not work properly
7+
if (NOT CYGWIN)
8+
configure_package_config_file("${CMAKE_CURRENT_SOURCE_DIR}/build/cmake/SqliteOrmConfig.cmake.in"
9+
"${CMAKE_CURRENT_BINARY_DIR}/SqliteOrmConfig.cmake"
10+
INSTALL_DESTINATION "${CMAKE_INSTALL_DIR}/sqlite_orm"
11+
PATH_VARS
12+
PACKAGE_INCLUDE_INSTALL_DIR
13+
PACKAGE_CMAKE_INSTALL_DIR
14+
)
15+
16+
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/SqliteOrmConfigVersion.cmake"
17+
VERSION ${sqlite_orm_VERSION}
18+
COMPATIBILITY SameMajorVersion
19+
)
20+
21+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/SqliteOrmConfig.cmake"
22+
"${CMAKE_CURRENT_BINARY_DIR}/SqliteOrmConfigVersion.cmake"
23+
DESTINATION "${CMAKE_INSTALL_DIR}/sqlite_orm")
24+
endif()
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
set(SQLITE_ORM_VERSION ${sqlite_orm_VERSION})
2+
3+
@PACKAGE_INIT@
4+
5+
set_and_check(SQLITE_ORM_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
6+
set_and_check(SQLITE_ORM_CMAKE_DIR "@PACKAGE_CMAKE_INSTALL_DIR@")
7+
8+
if (NOT TARGET sqlite_orm::sqlite_orm)
9+
include("${SQLITE_ORM_CMAKE_DIR}/SqliteOrmTargets.cmake")
10+
endif()
11+
12+
set(SQLITE_ORM_LIBRARIES sqlite_orm::sqlite_orm)
13+
14+
if ("${SQLITE_ORM_LIBRARIES}" STREQUAL "")
15+
message(FATAL_ERROR "sqlite_orm libraries were not found")
16+
endif()
17+
18+
if (NOT SqliteOrm_FIND_QUIETLY)
19+
message(STATUS "Found sqlite_orm: ${PACKAGE_PREFIX_DIR}")
20+
endif()
21+
22+
check_required_components(SqliteOrm)

0 commit comments

Comments
 (0)