Skip to content

Commit 089b338

Browse files
authored
Merge pull request #1 from KGGrande/dev
2 parents d0206b6 + 2994b26 commit 089b338

File tree

4 files changed

+94
-39
lines changed

4 files changed

+94
-39
lines changed
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build React Native Windows and Publish to NPM
1+
name: CD
22

33
on:
44
push:
@@ -9,7 +9,6 @@ permissions:
99

1010
jobs:
1111
build-react-native-windows:
12-
name: Build & Test React Native Windows
1312
runs-on: windows-2022
1413

1514
steps:
@@ -33,7 +32,6 @@ jobs:
3332
working-directory: ./example
3433

3534
publish-to-npm:
36-
name: Publish Package to NPM
3735
runs-on: ubuntu-latest
3836
needs: build-react-native-windows
3937

@@ -60,5 +58,6 @@ jobs:
6058
env:
6159
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
6260
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63-
# needed to release on github unless we use release-it ^19
61+
# https://github.com/release-it/release-it/issues/1238
62+
# Use release-it ^19 or set NODE_DEBUG
6463
NODE_DEBUG: release-it:*

.github/workflows/ci.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
name: CI
22
on:
3-
push:
4-
branches:
5-
- main
3+
# push:
4+
# branches:
5+
# - main
66
pull_request:
77
branches:
88
- main
@@ -51,7 +51,6 @@ jobs:
5151
run: yarn prepare && yarn codegen
5252

5353
build-react-native-windows:
54-
name: Build & Test React Native Windows
5554
runs-on: windows-2022
5655

5756
steps:

example/src/App.tsx

Lines changed: 75 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
TextInput,
1111
Alert,
1212
ActivityIndicator,
13+
Modal,
1314
} from 'react-native';
1415
import { openDatabase, SQLiteDatabase } from 'react-native-sqlite-windows';
1516

@@ -32,6 +33,9 @@ const App = () => {
3233
const [email, setEmail] = useState('');
3334
const [age, setAge] = useState('');
3435

36+
const [editVisible, setEditVisible] = useState(false);
37+
const [editUser, setEditUser] = useState<any | null>(null);
38+
const [editName, setEditName] = useState('');
3539
// Initialize database
3640
const initDatabase = async () => {
3741
try {
@@ -125,7 +129,7 @@ const App = () => {
125129
setLoading(true);
126130
const result = await db.executeSql(
127131
'INSERT INTO users (name, email, age) VALUES (?, ?, ?)',
128-
[name, email, parseInt(age)]
132+
[name, email, parseInt(age, 10)]
129133
);
130134

131135
// Ensure insertId is valid number
@@ -148,27 +152,27 @@ const App = () => {
148152
}
149153
};
150154

151-
// Update user
152-
// const updateUser = async (id: number, newName: string) => {
153-
// if (!db) return;
154-
155-
// try {
156-
// setLoading(true);
157-
// const result = await db.executeSql(
158-
// 'UPDATE users SET name = ? WHERE id = ?',
159-
// [newName, id]
160-
// );
161-
162-
// setStatus(`Updated ${result.rowsAffected} user(s)`);
163-
// Alert.alert('Success', `User updated successfully`);
164-
// await loadUsers();
165-
// } catch (error) {
166-
// setStatus(`Error updating user: ${error}`);
167-
// Alert.alert('Update Error', String(error));
168-
// } finally {
169-
// setLoading(false);
170-
// }
171-
// };
155+
//Update user
156+
const updateUser = async (id: number, newName: string) => {
157+
if (!db) return;
158+
159+
try {
160+
setLoading(true);
161+
const result = await db.executeSql(
162+
'UPDATE users SET name = ? WHERE id = ?',
163+
[newName, id]
164+
);
165+
166+
setStatus(`Updated ${result.rowsAffected} user(s)`);
167+
Alert.alert('Success', `User updated successfully`);
168+
await loadUsers();
169+
} catch (error) {
170+
setStatus(`Error updating user: ${error}`);
171+
Alert.alert('Update Error', String(error));
172+
} finally {
173+
setLoading(false);
174+
}
175+
};
172176

173177
// Delete user
174178
const deleteUser = async (id: number, userName: string) => {
@@ -486,14 +490,14 @@ const App = () => {
486490
<Text style={styles.userDetail}>Age: {user.age}</Text>
487491
</View>
488492
<View style={styles.userActions}>
489-
{/* <Button
493+
<Button
490494
title="Edit"
491495
onPress={() => {
492-
Alert.alert('Update Name', 'Enter new name:', (text) =>
493-
updateUser(user.id, text)
494-
);
496+
setEditUser(user);
497+
setEditName(user.name);
498+
setEditVisible(true);
495499
}}
496-
/> */}
500+
/>
497501
<Button
498502
title="Delete"
499503
color="red"
@@ -505,6 +509,37 @@ const App = () => {
505509
)}
506510
</View>
507511
)}
512+
{/* Edit Modal */}
513+
<Modal visible={editVisible} transparent animationType="fade">
514+
<View style={styles.modalOverlay}>
515+
<View style={styles.modalContainer}>
516+
<Text style={styles.sectionTitle}>Edit User</Text>
517+
<TextInput
518+
style={styles.input}
519+
placeholder="Enter new name"
520+
value={editName}
521+
onChangeText={setEditName}
522+
/>
523+
<View style={styles.buttonRow}>
524+
<Button
525+
title="Save"
526+
onPress={() => {
527+
if (editUser && editName.trim()) {
528+
updateUser(editUser.id, editName.trim());
529+
setEditVisible(false);
530+
Alert.alert('Success', 'User updated');
531+
}
532+
}}
533+
/>
534+
<Button
535+
title="Cancel"
536+
color="gray"
537+
onPress={() => setEditVisible(false)}
538+
/>
539+
</View>
540+
</View>
541+
</View>
542+
</Modal>
508543
</ScrollView>
509544
</SafeAreaView>
510545
);
@@ -604,6 +639,19 @@ const styles = StyleSheet.create({
604639
fontSize: 16,
605640
padding: 20,
606641
},
642+
modalOverlay: {
643+
flex: 1,
644+
backgroundColor: 'rgba(0,0,0,0.4)',
645+
justifyContent: 'center',
646+
alignItems: 'center',
647+
},
648+
modalContainer: {
649+
backgroundColor: 'white',
650+
padding: 20,
651+
borderRadius: 12,
652+
width: '80%',
653+
elevation: 5,
654+
},
607655
});
608656

609657
export default App;

windows/ReactNativeSqliteWindows/ReactNativeSqliteWindows.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "ReactNativeSqliteWindows.h"
33
#include "sqlite3.h" // native SQLite C API
44
#include <filesystem>
5+
#include <winrt/Windows.Storage.h>
56

67
namespace winrt::ReactNativeSqliteWindows
78
{
@@ -24,11 +25,19 @@ namespace winrt::ReactNativeSqliteWindows
2425

2526
std::wstring ReactNativeSqliteWindows::GetDatabasePath(std::string const& name)
2627
{
28+
29+
using namespace winrt::Windows::Storage;
30+
31+
// Convert the UTF-8 db name to UTF-16 for Windows
2732
std::wstring wname(name.begin(), name.end());
28-
std::filesystem::path folder = std::filesystem::temp_directory_path();
29-
std::filesystem::path fullPath = folder / (wname + L".db");
30-
OutputDebugStringW((L"GetDatabasePath: " + fullPath.wstring() + L"\n").c_str());
31-
return fullPath.wstring();
33+
34+
// Get the app’s local storage folder (safe, persistent)
35+
auto localFolder = ApplicationData::Current().LocalFolder().Path();
36+
37+
// Combine it with the database file name
38+
std::filesystem::path dbPath = std::filesystem::path(localFolder.c_str()) / (wname + L".db");
39+
40+
return dbPath.wstring();
3241
}
3342

3443
void ReactNativeSqliteWindows::open(std::string dbName, React::ReactPromise<std::string>&& promise) noexcept {

0 commit comments

Comments
 (0)